Skip to content

Commit 0ba41fe

Browse files
Release 1.1.7 - Added sounds support
1 parent a6a1720 commit 0ba41fe

File tree

6 files changed

+156
-8
lines changed

6 files changed

+156
-8
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
setGroup("net.elytrium")
10-
setVersion("1.1.6")
10+
setVersion("1.1.7")
1111

1212
compileJava {
1313
getOptions().setEncoding("UTF-8")

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
limboapiVersion=1.1.23
1+
limboapiVersion=1.1.26
22
velocityVersion=3.3.0-SNAPSHOT
3-
nettyVersion=4.1.106.Final
3+
nettyVersion=4.1.114.Final
44
serializerVersion=1.1.1

src/main/java/net/elytrium/limboreconnect/Config.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ public class Config extends YamlSerializable {
5858

5959
public World world;
6060
public Messages messages;
61+
public Sounds sounds;
6162
public boolean debug = false;
6263

6364

6465
public Config() {
6566
super(Config.CONFIG);
6667
this.world = new World();
6768
this.messages = new Messages();
69+
this.sounds = new Sounds();
6870
}
6971

7072

@@ -147,4 +149,24 @@ public Title(String title) {
147149
}
148150
}
149151
}
152+
153+
public static class Sounds {
154+
155+
public Sound waiting = new Sound("entity.experience_orb.pickup");
156+
public Sound connecting = new Sound("entity.player.levelup");
157+
158+
public static class Sound {
159+
160+
public String name;
161+
public float volume = 1.0f;
162+
public float pitch = 1.0f;
163+
164+
public Sound() {
165+
}
166+
167+
public Sound(String name) {
168+
this.name = name;
169+
}
170+
}
171+
}
150172
}

src/main/java/net/elytrium/limboreconnect/LimboReconnect.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package net.elytrium.limboreconnect;
1919

2020
import com.google.inject.Inject;
21+
import com.velocitypowered.api.command.CommandManager;
22+
import com.velocitypowered.api.command.CommandMeta;
2123
import com.velocitypowered.api.event.Subscribe;
2224
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
25+
import com.velocitypowered.api.network.ProtocolVersion;
2326
import com.velocitypowered.api.plugin.Plugin;
2427
import com.velocitypowered.api.plugin.PluginContainer;
2528
import com.velocitypowered.api.plugin.annotation.DataDirectory;
@@ -44,9 +47,12 @@
4447
import net.elytrium.limboapi.api.chunk.Dimension;
4548
import net.elytrium.limboapi.api.chunk.VirtualWorld;
4649
import net.elytrium.limboapi.api.file.WorldFile;
50+
import net.elytrium.limboapi.api.protocol.PacketDirection;
51+
import net.elytrium.limboapi.api.protocol.packets.PacketMapping;
4752
import net.elytrium.limboreconnect.commands.LimboReconnectCommand;
4853
import net.elytrium.limboreconnect.handler.ReconnectHandler;
4954
import net.elytrium.limboreconnect.listener.ReconnectListener;
55+
import net.elytrium.limboreconnect.protocol.packets.PlaySound;
5056
import net.kyori.adventure.text.Component;
5157
import net.kyori.adventure.text.serializer.ComponentSerializer;
5258
import net.kyori.adventure.title.Title;
@@ -71,12 +77,14 @@ public class LimboReconnect {
7177
private final Path configPath;
7278
private final Path dataDirectory;
7379
private final LimboFactory factory;
80+
private final CommandMeta commandMeta;
7481
private Limbo limbo;
7582

7683
@Inject
7784
public LimboReconnect(Logger logger, ProxyServer server, @DataDirectory Path dataDirectory) {
7885
setLogger(logger);
7986
this.server = server;
87+
this.commandMeta = server.getCommandManager().metaBuilder("limboreconnect").plugin(this).build();
8088

8189
this.dataDirectory = dataDirectory;
8290
this.configPath = dataDirectory.resolve("config.yml");
@@ -138,8 +146,27 @@ public void reload() {
138146
}
139147
}
140148

141-
this.limbo = this.factory.createLimbo(world).setName("LimboReconnect").setShouldRejoin(CONFIG.useLimbo)
142-
.setShouldRespawn(CONFIG.useLimbo).setGameMode(CONFIG.world.gamemode);
149+
this.limbo = this.factory.createLimbo(world)
150+
.setName("LimboReconnect")
151+
.setShouldRejoin(CONFIG.useLimbo)
152+
.setShouldRespawn(CONFIG.useLimbo)
153+
.setGameMode(CONFIG.world.gamemode)
154+
.registerPacket(PacketDirection.CLIENTBOUND, PlaySound.class, PlaySound::new, new PacketMapping[] {
155+
new PacketMapping(0x29, ProtocolVersion.MINECRAFT_1_7_2, true),
156+
new PacketMapping(0x19, ProtocolVersion.MINECRAFT_1_9, true),
157+
new PacketMapping(0x1a, ProtocolVersion.MINECRAFT_1_13, true),
158+
new PacketMapping(0x19, ProtocolVersion.MINECRAFT_1_14, true),
159+
new PacketMapping(0x1a, ProtocolVersion.MINECRAFT_1_15, true),
160+
new PacketMapping(0x19, ProtocolVersion.MINECRAFT_1_16, true),
161+
new PacketMapping(0x18, ProtocolVersion.MINECRAFT_1_16_2, true),
162+
new PacketMapping(0x19, ProtocolVersion.MINECRAFT_1_17, true),
163+
new PacketMapping(0x16, ProtocolVersion.MINECRAFT_1_19, true),
164+
new PacketMapping(0x17, ProtocolVersion.MINECRAFT_1_19_1, true),
165+
new PacketMapping(0x5e, ProtocolVersion.MINECRAFT_1_19_3, true),
166+
new PacketMapping(0x62, ProtocolVersion.MINECRAFT_1_19_4, true),
167+
new PacketMapping(0x64, ProtocolVersion.MINECRAFT_1_20_2, true),
168+
new PacketMapping(0x68, ProtocolVersion.MINECRAFT_1_21, true),
169+
});
143170

144171
this.offlineTitles.clear();
145172
CONFIG.messages.titles.titles.forEach(title -> this.offlineTitles.add(Title.title(
@@ -165,8 +192,9 @@ public void reload() {
165192

166193
this.server.getEventManager().unregisterListeners(this);
167194
this.server.getEventManager().register(this, new ReconnectListener(this));
168-
this.server.getCommandManager().unregister("limboreconnect");
169-
this.server.getCommandManager().register("limboreconnect", new LimboReconnectCommand(this));
195+
CommandManager commandManager = this.server.getCommandManager();
196+
commandManager.unregister("limboreconnect");
197+
commandManager.register(this.commandMeta, new LimboReconnectCommand(this));
170198
}
171199

172200
public void addPlayer(Player player, RegisteredServer server) {

src/main/java/net/elytrium/limboreconnect/handler/ReconnectHandler.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import net.elytrium.limboapi.api.Limbo;
2727
import net.elytrium.limboapi.api.LimboSessionHandler;
2828
import net.elytrium.limboapi.api.player.LimboPlayer;
29+
import net.elytrium.limboreconnect.Config;
2930
import net.elytrium.limboreconnect.LimboReconnect;
31+
import net.elytrium.limboreconnect.protocol.packets.PlaySound;
3032

3133
public class ReconnectHandler implements LimboSessionHandler {
3234

@@ -37,10 +39,18 @@ public class ReconnectHandler implements LimboSessionHandler {
3739
private boolean connected = true;
3840
private boolean connecting = false;
3941
private int titleIndex = -1;
42+
private final PlaySound waitSound;
43+
private final PlaySound connectSound;
4044

4145
public ReconnectHandler(LimboReconnect plugin, RegisteredServer server) {
4246
this.plugin = plugin;
4347
this.server = server;
48+
Config.Sounds sounds = CONFIG.sounds;
49+
double playerX = CONFIG.world.playerCoords.x;
50+
double playerY = CONFIG.world.playerCoords.y;
51+
double playerZ = CONFIG.world.playerCoords.z;
52+
this.waitSound = new PlaySound(sounds.waiting.name, playerX, playerY, playerZ, sounds.waiting.volume, sounds.waiting.pitch);
53+
this.connectSound = new PlaySound(sounds.connecting.name, playerX, playerY, playerZ, sounds.connecting.volume, sounds.connecting.pitch);
4454
}
4555

4656
@Override
@@ -57,6 +67,12 @@ public void onDisconnect() {
5767
this.connected = false;
5868
}
5969

70+
@Override
71+
public void onMove(double x, double y, double z) {
72+
this.waitSound.setPosition(x, y, z);
73+
this.connectSound.setPosition(x, y, z);
74+
}
75+
6076
private void tick() {
6177
if (!this.connected) {
6278
return;
@@ -75,6 +91,7 @@ private void tick() {
7591
this.connecting = true;
7692
this.titleIndex = -1;
7793
this.player.getScheduledExecutor().schedule(() -> {
94+
this.player.writePacket(this.connectSound);
7895
this.player.getProxyPlayer().resetTitle();
7996
this.player.disconnect(this.server);
8097
}, CONFIG.joinDelay, TimeUnit.MILLISECONDS);
@@ -95,7 +112,7 @@ private void tickMessages() {
95112
this.titleIndex = (this.titleIndex + 1) % this.plugin.offlineTitles.size();
96113
this.player.getProxyPlayer().showTitle(this.plugin.offlineTitles.get(this.titleIndex));
97114
}
98-
115+
this.player.writePacket(this.waitSound);
99116
this.player.getScheduledExecutor().schedule(this::tickMessages, CONFIG.messages.titles.showDelay * 50, TimeUnit.MILLISECONDS);
100117
}
101118
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (C) 2022 - 2024 Elytrium
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package net.elytrium.limboreconnect.protocol.packets;
19+
20+
import com.velocitypowered.api.network.ProtocolVersion;
21+
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
22+
import com.velocitypowered.proxy.protocol.MinecraftPacket;
23+
import com.velocitypowered.proxy.protocol.ProtocolUtils;
24+
import io.netty.buffer.ByteBuf;
25+
26+
public class PlaySound implements MinecraftPacket {
27+
28+
private final String soundName;
29+
private final float volume;
30+
private final float pitch;
31+
private int playerX;
32+
private int playerY;
33+
private int playerZ;
34+
35+
public PlaySound(String soundName, double x, double y, double z, float volume, float pitch) {
36+
this.soundName = soundName;
37+
this.setPosition(x, y, z);
38+
this.volume = volume;
39+
this.pitch = pitch;
40+
}
41+
42+
public PlaySound() {
43+
throw new IllegalStateException();
44+
}
45+
46+
@Override
47+
public void decode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
48+
throw new IllegalStateException();
49+
}
50+
51+
@Override
52+
public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
53+
if (protocolVersion.greaterThan(ProtocolVersion.MINECRAFT_1_19_1) && protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_18_2)) {
54+
ProtocolUtils.writeVarInt(byteBuf, 0);
55+
}
56+
ProtocolUtils.writeString(byteBuf, this.soundName);
57+
if (protocolVersion.greaterThan(ProtocolVersion.MINECRAFT_1_19_1) && protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_18_2)) {
58+
byteBuf.writeBoolean(false);
59+
}
60+
ProtocolUtils.writeVarInt(byteBuf, 0);
61+
byteBuf.writeInt(this.playerX);
62+
byteBuf.writeInt(this.playerY);
63+
byteBuf.writeInt(this.playerZ);
64+
byteBuf.writeFloat(this.volume);
65+
byteBuf.writeFloat(this.pitch);
66+
if (protocolVersion.greaterThan(ProtocolVersion.MINECRAFT_1_18_2)) {
67+
byteBuf.writeLong(0);
68+
}
69+
}
70+
71+
@Override
72+
public boolean handle(MinecraftSessionHandler minecraftSessionHandler) {
73+
return false;
74+
}
75+
76+
public void setPosition(double x, double y, double z) {
77+
this.playerX = (int) (x * 8);
78+
this.playerY = (int) (y * 8);
79+
this.playerZ = (int) (z * 8);
80+
}
81+
}

0 commit comments

Comments
 (0)