diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..c7fd9d077 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,35 @@ + +> **Disclaimer** +> +> We generally only accept PRs with small bug fixes or translations. +> In case you want to implement a new feature, please check if it's possible to do so using the [API](https://modrepo.de/minecraft/voicechat/api/overview). +> If the feature you want to implement is not possible with the API, please visit the `#api-development` channel in our Discord! +> If you deem a feature to be important enough to be included in the base mod/plugin, please get in contact with us first! + + + + + + + +- [ ] I confirm that I have implemented the changes in this PR myself. +- [ ] I agree to transfer all rights for the contributed work to the owner of this repository. +- [ ] I confirm I did **not** use any AI tools for this PR. +- [ ] I confirm that I tested all changes made in this PR thoroughly. +- [ ] I confirm that I followed the same code style as the rest of the repository. +- [ ] I confirm that there are no breaking protocol changes in this PR. + + +### Description + + + + +### Related issue(s) / PR(s) + + + + +### Screenshots / Recordings + + diff --git a/api/build.gradle b/api/build.gradle index ac5da5927..69ed4bc2e 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -3,10 +3,14 @@ plugins { id 'maven-publish' } -sourceCompatibility = JavaLanguageVersion.of(8) -targetCompatibility = JavaLanguageVersion.of(8) +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} -archivesBaseName = archives_base_name +base { + archivesName = archives_base_name +} version = version group = maven_group @@ -44,7 +48,7 @@ publishing { publications { voiceChatApi(MavenPublication) { artifactId archives_base_name - artifact(jar.archivePath) { + artifact(jar) { builtBy build classifier null } diff --git a/api/src/main/java/de/maxhenkel/voicechat/api/Entity.java b/api/src/main/java/de/maxhenkel/voicechat/api/Entity.java index 669cf4234..a1f4d07a4 100644 --- a/api/src/main/java/de/maxhenkel/voicechat/api/Entity.java +++ b/api/src/main/java/de/maxhenkel/voicechat/api/Entity.java @@ -19,4 +19,13 @@ public interface Entity { */ Position getPosition(); + /** + * @return the current eye position of the entity + */ + Position getEyePosition(); + + /** + * @return the level of the entity + */ + ServerLevel getLevel(); } diff --git a/api/src/main/java/de/maxhenkel/voicechat/api/MinecraftServer.java b/api/src/main/java/de/maxhenkel/voicechat/api/MinecraftServer.java new file mode 100644 index 000000000..ed766ffd9 --- /dev/null +++ b/api/src/main/java/de/maxhenkel/voicechat/api/MinecraftServer.java @@ -0,0 +1,48 @@ +package de.maxhenkel.voicechat.api; + +import java.util.List; +import java.util.UUID; + +public interface MinecraftServer { + + /** + * @return the actual server object + */ + Object getMinecraftServer(); + + /** + * @return the ip of the server, without port + */ + String getIp(); + + /** + * @return the port of the server + */ + int getPort(); + + /** + * @param playerUUID the UUID of the player + * @return the corresponding {@link ServerPlayer} object + */ + ServerPlayer getPlayer(UUID playerUUID); + + /** + * @return a list of all players in the server + */ + List getPlayers(); + + /** + * @return whether the server is a dedicated server + */ + boolean isDedicated(); + + /** + * @return whether the server has 'online-mode' set to true + */ + boolean usesAuthentication(); + + /** + * @return the permission level at which a user is considered an operator + */ + int getOperatorUserPermissionLevel(); +} diff --git a/api/src/main/java/de/maxhenkel/voicechat/api/Player.java b/api/src/main/java/de/maxhenkel/voicechat/api/Player.java index 686fe2c25..82eece704 100644 --- a/api/src/main/java/de/maxhenkel/voicechat/api/Player.java +++ b/api/src/main/java/de/maxhenkel/voicechat/api/Player.java @@ -2,9 +2,4 @@ public interface Player extends Entity { - /** - * @return the actual player object - */ - Object getPlayer(); - } diff --git a/api/src/main/java/de/maxhenkel/voicechat/api/ServerLevel.java b/api/src/main/java/de/maxhenkel/voicechat/api/ServerLevel.java index 6cf21f38a..26de90f78 100644 --- a/api/src/main/java/de/maxhenkel/voicechat/api/ServerLevel.java +++ b/api/src/main/java/de/maxhenkel/voicechat/api/ServerLevel.java @@ -1,5 +1,7 @@ package de.maxhenkel.voicechat.api; +import java.util.List; + public interface ServerLevel { /** @@ -7,4 +9,9 @@ public interface ServerLevel { */ Object getServerLevel(); + /** + * @return the list of players in the level + */ + List players(); + } diff --git a/api/src/main/java/de/maxhenkel/voicechat/api/ServerPlayer.java b/api/src/main/java/de/maxhenkel/voicechat/api/ServerPlayer.java index d0ef08b71..a57f7c8b4 100644 --- a/api/src/main/java/de/maxhenkel/voicechat/api/ServerPlayer.java +++ b/api/src/main/java/de/maxhenkel/voicechat/api/ServerPlayer.java @@ -1,10 +1,28 @@ package de.maxhenkel.voicechat.api; +import javax.annotation.Nullable; + public interface ServerPlayer extends Player { /** - * @return the level of the player + * @return the player's name */ - ServerLevel getServerLevel(); + String getName(); + /** + * @return the player the user's camera is using + */ + @Nullable + ServerPlayer getCameraPlayer(); + + /** + * @return whether the player is in spectator mode + */ + boolean isSpectator(); + + /** + * @param operatorUserPermissionLevel the permission level to check against + * @return whether the player has the permissions + */ + boolean hasPermissions(int operatorUserPermissionLevel); } diff --git a/api/src/main/java/de/maxhenkel/voicechat/api/VoicechatApi.java b/api/src/main/java/de/maxhenkel/voicechat/api/VoicechatApi.java index 9c17758f7..6cc7d23cf 100644 --- a/api/src/main/java/de/maxhenkel/voicechat/api/VoicechatApi.java +++ b/api/src/main/java/de/maxhenkel/voicechat/api/VoicechatApi.java @@ -63,40 +63,6 @@ public interface VoicechatApi { */ AudioConverter getAudioConverter(); - /** - * Creates an entity object from an actual entity. - * - * @param entity the entity implementation of your mod/plugin loader - * @return the entity object - */ - Entity fromEntity(Object entity); - - /** - * Creates a level object from an actual level. - * - * @param serverLevel the level implementation of your mod/plugin loader - * @return the level - */ - ServerLevel fromServerLevel(Object serverLevel); - - /** - * Creates a player object from an actual player. - * - * @param serverPlayer the player implementation of your mod/plugin loader - * @return the player - */ - ServerPlayer fromServerPlayer(Object serverPlayer); - - /** - * Creates a new position object. - * - * @param x the X position - * @param y the Y position - * @param z the Z position - * @return the position with the provided coordinates - */ - Position createPosition(double x, double y, double z); - /** * Don't forget to register your category with {@link VoicechatServerApi#registerVolumeCategory(VolumeCategory)} or {@link VoicechatClientApi#registerClientVolumeCategory(VolumeCategory)} * diff --git a/build.gradle b/build.gradle index d7abdc309..f49cdb22c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'com.gradleup.shadow' version "${shadow_version}" apply false - id 'com.matthewprenger.cursegradle' version "${cursegradle_version}" apply false + id 'de.maxhenkel.cursegradle' version "${cursegradle_version}" apply false id 'com.modrinth.minotaur' version "${minotaur_version}" apply false id 'mod-update' version "${mod_update_version}" apply false id 'fabric-loom' version "${fabric_loom_version}" apply false @@ -17,7 +17,7 @@ tasks.register('01-publishQuilt', GradleBuild) { tasks.register('02-publishForge') { group = 'voicechat' doLast { - runGradleTasks(['common:clean', 'common-client:clean', 'forge:clean'], ['forge:curseforge', 'forge:modrinth', 'forge:modUpdate']) + runGradleTask('uploadMod', false, file('forge')) } } diff --git a/common-client/gradle.properties b/common-client/gradle.properties index 909bcf6d0..b7c0be20f 100644 --- a/common-client/gradle.properties +++ b/common-client/gradle.properties @@ -1,6 +1,6 @@ mod_loader=fabric -included_projects=:api, :common +included_projects=:api, :core, :common enable_curseforge_upload=false enable_modrinth_upload=false diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/AdjustVolumeList.java b/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/AdjustVolumeList.java index c2aa00e9d..58fca1c4a 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/AdjustVolumeList.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/AdjustVolumeList.java @@ -3,6 +3,7 @@ import com.google.common.collect.Lists; import de.maxhenkel.voicechat.VoicechatClient; import de.maxhenkel.voicechat.gui.widgets.ListScreenListBase; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import de.maxhenkel.voicechat.plugins.impl.VolumeCategoryImpl; import de.maxhenkel.voicechat.voice.client.ClientManager; import de.maxhenkel.voicechat.voice.common.PlayerState; @@ -79,7 +80,7 @@ public void updateFilter() { if (volumeEntry instanceof PlayerVolumeEntry playerVolumeEntry) { return playerVolumeEntry.getState() == null || !playerVolumeEntry.getState().getName().toLowerCase(Locale.ROOT).contains(filter); } else if (volumeEntry instanceof CategoryVolumeEntry categoryVolumeEntry) { - return !categoryVolumeEntry.getCategory().getSearchName().toLowerCase(Locale.ROOT).contains(filter); + return !MinecraftCompatibilityManager.getCategorySearchName(categoryVolumeEntry.getCategory()).toLowerCase(Locale.ROOT).contains(filter); } return true; }); @@ -105,7 +106,7 @@ private String volumeEntryToSearchString(VolumeEntry entry) { if (entry instanceof PlayerVolumeEntry playerVolumeEntry) { return playerVolumeEntry.getState() == null ? "" : playerVolumeEntry.getState().getName(); } else if (entry instanceof CategoryVolumeEntry categoryVolumeEntry) { - return categoryVolumeEntry.getCategory().getSearchName(); + return MinecraftCompatibilityManager.getCategorySearchName(categoryVolumeEntry.getCategory()); } return ""; } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/CategoryVolumeEntry.java b/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/CategoryVolumeEntry.java index 1823551bc..0a3be209a 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/CategoryVolumeEntry.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/gui/volume/CategoryVolumeEntry.java @@ -1,12 +1,12 @@ package de.maxhenkel.voicechat.gui.volume; import de.maxhenkel.voicechat.VoicechatClient; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import de.maxhenkel.voicechat.plugins.impl.VolumeCategoryImpl; import de.maxhenkel.voicechat.voice.client.ClientManager; import de.maxhenkel.voicechat.voice.client.ClientVoicechat; import de.maxhenkel.voicechat.voice.common.AudioUtils; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; public class CategoryVolumeEntry extends VolumeEntry { @@ -27,10 +27,10 @@ public VolumeCategoryImpl getCategory() { @Override public void renderElement(GuiGraphics guiGraphics, int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean hovered, float delta, int skinX, int skinY, int textX, int textY) { guiGraphics.blit(texture, skinX, skinY, SKIN_SIZE, SKIN_SIZE, 16, 16, 16, 16, 16, 16); - renderScrollingString(guiGraphics, category.getDisplayName(), top, left, width, height, PLAYER_NAME_COLOR); + renderScrollingString(guiGraphics, MinecraftCompatibilityManager.getCategoryDisplayName(category), top, left, width, height, PLAYER_NAME_COLOR); if (hovered && category.getDescription() != null) { screen.postRender(() -> { - guiGraphics.renderTooltip(minecraft.font, category.getDisplayDescription(), mouseX, mouseY); + guiGraphics.renderTooltip(minecraft.font, MinecraftCompatibilityManager.getCategoryDisplayDescription(category), mouseX, mouseY); }); } } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/gui/widgets/MicTestButton.java b/common-client/src/main/java/de/maxhenkel/voicechat/gui/widgets/MicTestButton.java index 0dd5e8beb..d9add96b2 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/gui/widgets/MicTestButton.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/gui/widgets/MicTestButton.java @@ -172,7 +172,7 @@ public VoiceThread(Consumer onMicError) throws SpeakerExcep SoundManager soundManager; if (client == null) { - soundManager = new SoundManager(); + soundManager = SoundManager.create(); ownSoundManager = soundManager; } else { soundManager = client.getSoundManager(); diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/intercompatibility/ClientCrossSideManager.java b/common-client/src/main/java/de/maxhenkel/voicechat/intercompatibility/ClientCrossSideManager.java index ca8b35ef5..915cf145d 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/intercompatibility/ClientCrossSideManager.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/intercompatibility/ClientCrossSideManager.java @@ -5,8 +5,7 @@ import de.maxhenkel.voicechat.voice.client.ClientManager; import de.maxhenkel.voicechat.voice.client.ClientVoicechat; import de.maxhenkel.voicechat.voice.client.ClientVoicechatConnection; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.dedicated.DedicatedServer; +import de.maxhenkel.voicechat.api.MinecraftServer; public class ClientCrossSideManager extends CrossSideManager { @@ -36,7 +35,7 @@ public boolean useNatives() { @Override public boolean shouldRunVoiceChatServer(MinecraftServer server) { - return server instanceof DedicatedServer || VoicechatClient.CLIENT_CONFIG == null || VoicechatClient.CLIENT_CONFIG.runLocalServer.get(); + return server.isDedicated() || VoicechatClient.CLIENT_CONFIG == null || VoicechatClient.CLIENT_CONFIG.runLocalServer.get(); } } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/net/ClientServerNetManager.java b/common-client/src/main/java/de/maxhenkel/voicechat/net/ClientServerNetManager.java index 728ef9cbd..721e2424f 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/net/ClientServerNetManager.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/net/ClientServerNetManager.java @@ -5,6 +5,7 @@ import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.resources.ResourceLocation; public abstract class ClientServerNetManager extends NetManager { @@ -13,7 +14,7 @@ public static void sendToServer(Packet packet) { packet.toBytes(buffer); ClientPacketListener connection = Minecraft.getInstance().getConnection(); if (connection != null && connection.getLevel() != null) { - connection.send(new ServerboundCustomPayloadPacket(packet.getIdentifier(), buffer)); + connection.send(new ServerboundCustomPayloadPacket(new ResourceLocation(packet.getIdentifier().key(), packet.getIdentifier().value()), buffer)); } } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/ClientLocationalAudioChannelImpl.java b/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/ClientLocationalAudioChannelImpl.java index 187274357..18ffdf233 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/ClientLocationalAudioChannelImpl.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/ClientLocationalAudioChannelImpl.java @@ -5,7 +5,6 @@ import de.maxhenkel.voicechat.voice.client.ClientUtils; import de.maxhenkel.voicechat.voice.common.LocationSoundPacket; import de.maxhenkel.voicechat.voice.common.SoundPacket; -import net.minecraft.world.phys.Vec3; import java.util.UUID; @@ -22,7 +21,7 @@ public ClientLocationalAudioChannelImpl(UUID id, Position position) { @Override protected SoundPacket createSoundPacket(short[] rawAudio) { - return new LocationSoundPacket(id, id, rawAudio, new Vec3(position.getX(), position.getY(), position.getZ()), distance, category); + return new LocationSoundPacket(id, id, rawAudio, position, distance, category); } @Override diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/OpenALSoundEventImpl.java b/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/OpenALSoundEventImpl.java index 038113ffa..94b7d7f2b 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/OpenALSoundEventImpl.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/OpenALSoundEventImpl.java @@ -2,7 +2,6 @@ import de.maxhenkel.voicechat.api.Position; import de.maxhenkel.voicechat.api.events.OpenALSoundEvent; -import de.maxhenkel.voicechat.plugins.impl.PositionImpl; import javax.annotation.Nullable; import java.util.UUID; @@ -10,14 +9,14 @@ public class OpenALSoundEventImpl extends ClientEventImpl implements OpenALSoundEvent, OpenALSoundEvent.Pre, OpenALSoundEvent.Post { @Nullable - protected PositionImpl position; + protected Position position; @Nullable protected UUID channelId; @Nullable protected String category; protected int source; - public OpenALSoundEventImpl(@Nullable UUID channelId, @Nullable PositionImpl position, @Nullable String category, int source) { + public OpenALSoundEventImpl(@Nullable UUID channelId, @Nullable Position position, @Nullable String category, int source) { this.channelId = channelId; this.position = position; this.category = category; diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioChannel.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioChannel.java index 2eb095d83..ff06317de 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioChannel.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioChannel.java @@ -6,6 +6,7 @@ import de.maxhenkel.voicechat.config.CategoryVolumeConfig; import de.maxhenkel.voicechat.debug.VoicechatUncaughtExceptionHandler; import de.maxhenkel.voicechat.integration.freecam.FreecamUtil; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import de.maxhenkel.voicechat.plugins.ClientPluginManager; import de.maxhenkel.voicechat.natives.OpusManager; import de.maxhenkel.voicechat.voice.client.speaker.Speaker; @@ -116,7 +117,7 @@ public void run() { if (packet instanceof PlayerSoundPacket playerSoundPacket) { ClientPluginManager.instance().onReceiveEntityClientSound(uuid, playerSoundPacket.getSender(), new short[0], playerSoundPacket.isWhispering(), playerSoundPacket.getDistance()); } else if (packet instanceof LocationSoundPacket locationSoundPacket) { - ClientPluginManager.instance().onReceiveLocationalClientSound(uuid, new short[0], locationSoundPacket.getLocation(), locationSoundPacket.getDistance()); + ClientPluginManager.instance().onReceiveLocationalClientSound(uuid, new short[0], MinecraftCompatibilityManager.getVec3(locationSoundPacket.getLocation()), locationSoundPacket.getDistance()); } else if (packet instanceof GroupSoundPacket) { ClientPluginManager.instance().onReceiveStaticClientSound(uuid, new short[0]); } @@ -257,13 +258,13 @@ private void writeToSpeaker(SoundPacket packet, short[] monoData) { float recordingVolume = deathVolume; appendRecording(() -> PositionalAudioUtils.convertToStereoForRecording(soundPacket.getDistance(), pos, processedMonoData, recordingVolume)); } else if (packet instanceof LocationSoundPacket p) { - short[] processedMonoData = ClientPluginManager.instance().onReceiveLocationalClientSound(uuid, monoData, p.getLocation(), p.getDistance()); - if (FreecamUtil.getDistanceTo(p.getLocation()) > p.getDistance() + 1D) { + short[] processedMonoData = ClientPluginManager.instance().onReceiveLocationalClientSound(uuid, monoData, MinecraftCompatibilityManager.getVec3(p.getLocation()), p.getDistance()); + if (FreecamUtil.getDistanceTo(MinecraftCompatibilityManager.getVec3(p.getLocation())) > p.getDistance() + 1D) { return; } - speaker.play(processedMonoData, volume, p.getLocation(), p.getCategory(), p.getDistance()); + speaker.play(processedMonoData, volume, MinecraftCompatibilityManager.getVec3(p.getLocation()), p.getCategory(), p.getDistance()); client.getTalkCache().updateLevel(uuid, category, false, processedMonoData); - appendRecording(() -> PositionalAudioUtils.convertToStereoForRecording(p.getDistance(), p.getLocation(), processedMonoData)); + appendRecording(() -> PositionalAudioUtils.convertToStereoForRecording(p.getDistance(), MinecraftCompatibilityManager.getVec3(p.getLocation()), processedMonoData)); } } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioRecorder.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioRecorder.java index 03928011b..a21b195ef 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioRecorder.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/AudioRecorder.java @@ -293,7 +293,7 @@ private void send(Component msg) { Minecraft mc = Minecraft.getInstance(); LocalPlayer player = mc.player; if (player != null && mc.level != null) { - player.sendSystemMessage(msg); + mc.execute(() -> player.sendSystemMessage(msg)); } else { Voicechat.LOGGER.info("{}", msg.getString()); } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/ClientVoicechat.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/ClientVoicechat.java index 9ffd0e2dd..4b983bf44 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/ClientVoicechat.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/ClientVoicechat.java @@ -99,7 +99,7 @@ public void reloadSoundManager() throws SpeakerException { if (soundManager != null) { soundManager.close(); } - soundManager = new SoundManager(); + soundManager = SoundManager.create(); } public void reloadAudio() { diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/PositionalAudioUtils.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/PositionalAudioUtils.java index 731b14f6c..90e9a94d9 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/PositionalAudioUtils.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/PositionalAudioUtils.java @@ -23,7 +23,7 @@ public class PositionalAudioUtils { private static float[] getStereoVolume(Vec3 cameraPos, float yRot, Vec3 soundPos) { Vec3 d = soundPos.subtract(cameraPos).normalize(); Vec2 diff = new Vec2((float) d.x, (float) d.z); - float diffAngle = Utils.angle(diff, new Vec2(-1F, 0F)); + float diffAngle = Utils.angle(diff.x, -1F, diff.y, 0F); float angle = Utils.normalizeAngle(diffAngle - (yRot % 360F)); float dif = (float) (Math.abs(cameraPos.y - soundPos.y) / 32); diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/SoundManager.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/SoundManager.java index 9a06bcf2a..abc5f7dad 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/SoundManager.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/SoundManager.java @@ -24,28 +24,81 @@ public class SoundManager { private final ALCapabilities alCaps; private final float maxGain; - public SoundManager(@Nullable String deviceName) throws SpeakerException { + public SoundManager(@Nullable String deviceName, long device, long context, ALCCapabilities alcCaps, ALCapabilities alCaps, float maxGain) { this.deviceName = deviceName; + this.device = device; + this.context = context; + this.alcCaps = alcCaps; + this.alCaps = alCaps; + this.maxGain = maxGain; + } - device = openSpeaker(deviceName); - context = ALC11.alcCreateContext(device, (IntBuffer) null); + public static SoundManager create() throws SpeakerException { + return create(VoicechatClient.CLIENT_CONFIG.speaker.get()); + } - alcCaps = ALC.createCapabilities(device); - alCaps = AL.createCapabilities(alcCaps); + public static SoundManager create(@Nullable String deviceName) throws SpeakerException { + long prevContext = ALC11.alcGetCurrentContext(); + long prevDevice = (prevContext != 0L) ? ALC11.alcGetContextsDevice(prevContext) : 0L; + try { + long device = openSpeaker(deviceName); + long context = ALC11.alcCreateContext(device, (IntBuffer) null); + if (context == 0L) { + int error = ALC11.alcGetError(device); + ALC11.alcCloseDevice(device); + checkAlcError(device); + throw new SpeakerException(String.format("Failed to create OpenAL context: %s", getAlcError(error))); + } + if (!ALC11.alcMakeContextCurrent(context)) { + int error = ALC11.alcGetError(device); + ALC11.alcDestroyContext(context); + checkAlcError(device); + ALC11.alcCloseDevice(device); + checkAlcError(device); + throw new SpeakerException(String.format("Failed to make OpenAL context current: %s", getAlcError(error))); + } - if (alCaps.AL_SOFT_gain_clamp_ex) { - maxGain = AL11.alGetFloat(SOFTGainClampEx.AL_GAIN_LIMIT_SOFT); - checkAlcError(device); - } else { - maxGain = 1F; - Voicechat.LOGGER.warn("OpenAL extension 'AL_SOFT_gain_clamp_ex' not supported - Voice chat volume can't exceed 100%"); - } + ALCCapabilities alcCaps = ALC.createCapabilities(device); + ALCapabilities alCaps = AL.createCapabilities(alcCaps); - ClientPluginManager.instance().onCreateALContext(context, device); - } + float maxGain; - public SoundManager() throws SpeakerException { - this(VoicechatClient.CLIENT_CONFIG.speaker.get()); + if (alCaps.AL_SOFT_gain_clamp_ex) { + maxGain = AL11.alGetFloat(SOFTGainClampEx.AL_GAIN_LIMIT_SOFT); + checkAlcError(device); + } else { + maxGain = 1F; + Voicechat.LOGGER.warn("OpenAL extension 'AL_SOFT_gain_clamp_ex' not supported - Voice chat volume can't exceed 100%"); + } + + ClientPluginManager.instance().onCreateALContext(context, device); + + return new SoundManager(deviceName, device, context, alcCaps, alCaps, maxGain); + } catch (SpeakerException speakerException) { + throw speakerException; + } catch (Throwable t) { + throw new SpeakerException("Failed to initialize OpenAL context", t); + } finally { + try { + if (prevContext != 0L) { + if (!ALC11.alcMakeContextCurrent(prevContext)) { + if (prevDevice != 0L) { + int error = ALC11.alcGetError(prevDevice); + Voicechat.LOGGER.error("Failed to restore previous OpenAL context ({}): {}", prevContext, getAlcError(error)); + } else { + Voicechat.LOGGER.error("Failed to restore previous OpenAL context ({}): Device not found", prevContext); + } + } else { + if (prevDevice != 0L) { + ALCCapabilities prevAlcCaps = ALC.createCapabilities(prevDevice); + AL.createCapabilities(prevAlcCaps); + } + } + } + } catch (Throwable t) { + Voicechat.LOGGER.warn("Failed to restore previous OpenAL context", t); + } + } } public void close() { @@ -55,8 +108,9 @@ public void close() { checkAlcError(device); } if (device != 0L) { - ALC11.alcCloseDevice(device); - checkAlcError(device); + if (!ALC11.alcCloseDevice(device)) { + checkAlcError(device); + } } context = 0; device = 0; @@ -70,53 +124,59 @@ public boolean isClosed() { return context == 0 || device == 0; } - private long openSpeaker(@Nullable String name) throws SpeakerException { + private static long openSpeaker(@Nullable String name) throws SpeakerException { try { return tryOpenSpeaker(name); } catch (SpeakerException e) { - if (name != null) { - Voicechat.LOGGER.warn("Failed to open audio device '{}', falling back to default", name); - } - try { - return tryOpenSpeaker(getDefaultSpeaker()); - } catch (SpeakerException ex) { - return tryOpenSpeaker(null); + if (name == null) { + throw e; } + Voicechat.LOGGER.warn("Failed to open audio device '{}', falling back to default", name); + return tryOpenSpeaker(null); } } - private long tryOpenSpeaker(@Nullable String string) throws SpeakerException { - long l = ALC11.alcOpenDevice(string); - if (l == 0L) { - throw new SpeakerException("Failed to open audio device: Audio device not found"); + private static long tryOpenSpeaker(@Nullable String string) throws SpeakerException { + long device = ALC11.alcOpenDevice(string); + if (device == 0L) { + throw new SpeakerException(String.format("Failed to open audio device: Audio device '%s' not found", string)); } int error = ALC11.alcGetError(device); if (error != ALC11.ALC_NO_ERROR) { - if (!ALC11.alcCloseDevice(l)) { + if (!ALC11.alcCloseDevice(device)) { Voicechat.LOGGER.warn("Failed to close audio device"); } throw new SpeakerException(String.format("Failed to open audio device: %s", getAlcError(error))); } - return l; + return device; } - @Nullable - public static String getDefaultSpeaker() { - if (!canEnumerate()) { - return null; + public static List getAllSpeakers() { + List devices = null; + if (canEnumerateAll()) { + devices = ALUtil.getStringList(0L, ALC11.ALC_ALL_DEVICES_SPECIFIER); + } else { + Voicechat.LOGGER.warn("Extension ALC_ENUMERATE_ALL_EXT is not present"); + } + boolean canEnumerate = canEnumerate(); + if (devices == null && !canEnumerate) { + Voicechat.LOGGER.warn("Extension ALC_ENUMERATION_EXT is not present"); } - String defaultSpeaker = ALC11.alcGetString(0L, ALC11.ALC_ALL_DEVICES_SPECIFIER); - checkAlcError(0L); - return defaultSpeaker; + if (devices == null && canEnumerate) { + devices = ALUtil.getStringList(0L, ALC11.ALC_DEVICE_SPECIFIER); + } + if (devices == null) { + devices = Collections.emptyList(); + } + return devices; } - public static List getAllSpeakers() { - if (!canEnumerate()) { - return Collections.emptyList(); - } - List devices = ALUtil.getStringList(0L, ALC11.ALC_ALL_DEVICES_SPECIFIER); - checkAlcError(0L); - return devices == null ? Collections.emptyList() : devices; + public static boolean canEnumerateAll() { + return ALC11.alcIsExtensionPresent(0L, "ALC_ENUMERATE_ALL_EXT"); + } + + public static boolean canEnumerate() { + return ALC11.alcIsExtensionPresent(0L, "ALC_ENUMERATION_EXT"); } public void runInContext(Executor executor, Runnable runnable) { @@ -167,8 +227,8 @@ public static boolean checkAlcError(long device) { return true; } - private static String getAlError(int i) { - switch (i) { + public static String getAlError(int errorCode) { + switch (errorCode) { case AL11.AL_INVALID_NAME: return "Invalid name"; case AL11.AL_INVALID_ENUM: @@ -180,7 +240,7 @@ private static String getAlError(int i) { case AL11.AL_OUT_OF_MEMORY: return "Out of memory"; default: - return "Unknown error"; + return String.format("Error %#X", errorCode); } } @@ -211,10 +271,4 @@ public static String cleanDeviceName(String name) { return matcher.group(1); } - public static boolean canEnumerate() { - boolean present = ALC11.alcIsExtensionPresent(0L, "ALC_ENUMERATE_ALL_EXT"); - checkAlcError(0L); - return present; - } - } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/TestSoundPlayer.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/TestSoundPlayer.java index cdc716f75..a4d7910a9 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/TestSoundPlayer.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/TestSoundPlayer.java @@ -68,7 +68,7 @@ private static void play(Runnable onDone) { return; } } else { - soundManager = new SoundManager(); + soundManager = SoundManager.create(); ownSoundManager = true; } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/VolumeManager.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/VolumeManager.java index 8174ba49c..94fc69da5 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/VolumeManager.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/VolumeManager.java @@ -71,7 +71,7 @@ private static double getMaximumMultiplier(short[] audio, double multiplier) { } if (max == 0) { - return 1D; + return multiplier; } return Math.min(multiplier, (double) MAX_AMPLIFICATION / (double) max); } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/microphone/ALMicrophone.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/microphone/ALMicrophone.java index 5e9f85316..6e4e92408 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/microphone/ALMicrophone.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/microphone/ALMicrophone.java @@ -30,6 +30,9 @@ public void open() throws MicrophoneException { if (isOpen()) { throw new MicrophoneException("Microphone already open"); } + if (!canCapture()) { + throw new MicrophoneException("Extension 'ALC_EXT_CAPTURE' not supported"); + } device = openMic(deviceName); } @@ -75,8 +78,9 @@ public void close() { return; } stop(); - ALC11.alcCaptureCloseDevice(device); - SoundManager.checkAlcError(device); + if (!ALC11.alcCaptureCloseDevice(device)) { + SoundManager.checkAlcError(device); + } device = 0; } @@ -114,43 +118,45 @@ private long openMic(@Nullable String name) throws MicrophoneException { try { return tryOpenMic(name); } catch (MicrophoneException e) { - if (name != null) { - Voicechat.LOGGER.warn("Failed to open microphone '{}', falling back to default microphone", name); - } - try { - return tryOpenMic(getDefaultMicrophone()); - } catch (MicrophoneException ex) { - return tryOpenMic(null); + if (name == null) { + throw e; } + Voicechat.LOGGER.warn("Failed to open microphone '{}', falling back to default microphone", name); + return tryOpenMic(null); } } private long tryOpenMic(@Nullable String string) throws MicrophoneException { long device = ALC11.alcCaptureOpenDevice(string, sampleRate, EXTFloat32.AL_FORMAT_MONO_FLOAT32, bufferSize); if (device == 0L) { - SoundManager.checkAlcError(0L); - throw new MicrophoneException(String.format("Failed to open microphone: %s", SoundManager.getAlcError(0))); + throw new MicrophoneException("Failed to open microphone"); } SoundManager.checkAlcError(device); return device; } - @Nullable - public static String getDefaultMicrophone() { - if (!SoundManager.canEnumerate()) { - return null; - } - String mic = ALC11.alcGetString(0L, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER); - SoundManager.checkAlcError(0L); - return mic; - } - public static List getAllMicrophones() { - if (!SoundManager.canEnumerate()) { + if (!canCapture()) { + Voicechat.LOGGER.warn("Extension ALC_EXT_CAPTURE is not present"); + return Collections.emptyList(); + } + if (!canEnumerate()) { + Voicechat.LOGGER.warn("Extension ALC_ENUMERATION_EXT is not present"); return Collections.emptyList(); } List devices = ALUtil.getStringList(0L, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER); - SoundManager.checkAlcError(0L); - return devices == null ? Collections.emptyList() : devices; + if (devices == null) { + Voicechat.LOGGER.warn("Failed to list available microphones"); + return Collections.emptyList(); + } + return devices; + } + + public static boolean canCapture() { + return ALC11.alcIsExtensionPresent(0L, "ALC_EXT_CAPTURE"); + } + + public static boolean canEnumerate() { + return ALC11.alcIsExtensionPresent(0L, "ALC_ENUMERATION_EXT"); } } diff --git a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/speaker/SpeakerException.java b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/speaker/SpeakerException.java index 5af01d47c..66680112a 100644 --- a/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/speaker/SpeakerException.java +++ b/common-client/src/main/java/de/maxhenkel/voicechat/voice/client/speaker/SpeakerException.java @@ -8,4 +8,8 @@ public SpeakerException(String message) { super(message); } + public SpeakerException(String message, Throwable cause) { + super(message, cause); + } + } diff --git a/common/gradle.properties b/common/gradle.properties index 1ffc5c7d9..b1380e9a0 100644 --- a/common/gradle.properties +++ b/common/gradle.properties @@ -1,6 +1,6 @@ mod_loader=fabric -included_projects=:api +included_projects=:api, :core enable_curseforge_upload=false enable_modrinth_upload=false diff --git a/common/src/main/java/de/maxhenkel/voicechat/command/VoicechatCommands.java b/common/src/main/java/de/maxhenkel/voicechat/command/VoicechatCommands.java index 0dab60187..bb6964169 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/command/VoicechatCommands.java +++ b/common/src/main/java/de/maxhenkel/voicechat/command/VoicechatCommands.java @@ -8,6 +8,7 @@ import com.mojang.brigadier.tree.CommandNode; import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import de.maxhenkel.voicechat.permission.Permission; import de.maxhenkel.voicechat.permission.PermissionManager; import de.maxhenkel.voicechat.voice.common.PlayerState; @@ -53,7 +54,7 @@ public static void register(CommandDispatcher dispatcher) { return 1; } - if (!Voicechat.SERVER.isCompatible(player)) { + if (!Voicechat.SERVER.isCompatible(MinecraftCompatibilityManager.fromServerPlayer(player))) { commandSource.getSource().sendSuccess(() -> Component.translatable("message.voicechat.player_no_voicechat", player.getDisplayName(), CommonCompatibilityManager.INSTANCE.getModName()), false); return 1; } @@ -122,7 +123,7 @@ public void onTimeout(int attempts) { return 1; } - if (!Voicechat.SERVER.isCompatible(player)) { + if (!Voicechat.SERVER.isCompatible(MinecraftCompatibilityManager.fromServerPlayer(player))) { commandSource.getSource().sendSuccess(() -> Component.translatable("message.voicechat.player_no_voicechat", player.getDisplayName(), CommonCompatibilityManager.INSTANCE.getModName()), false); return 1; } @@ -191,7 +192,7 @@ public void onTimeout(int attempts) { return 1; } - server.getGroupManager().leaveGroup(source); + server.getGroupManager().leaveGroup(MinecraftCompatibilityManager.fromServerPlayer(source)); commandSource.getSource().sendSuccess(() -> Component.translatable("message.voicechat.leave_successful"), false); return 1; })); @@ -212,7 +213,7 @@ private static Server joinGroup(CommandSourceStack source) throws CommandSyntaxE } ServerPlayer player = source.getPlayerOrException(); - if (!PermissionManager.INSTANCE.GROUPS_PERMISSION.hasPermission(player)) { + if (!PermissionManager.INSTANCE.GROUPS_PERMISSION.hasPermission(MinecraftCompatibilityManager.fromServerPlayer(player))) { source.sendSuccess(() -> Component.translatable("message.voicechat.no_group_permission"), false); return null; } @@ -257,7 +258,7 @@ private static int joinGroup(CommandSourceStack source, Server server, UUID grou return 1; } - server.getGroupManager().joinGroup(group, source.getPlayerOrException(), password); + server.getGroupManager().joinGroup(group, MinecraftCompatibilityManager.fromServerPlayer(source.getPlayerOrException()), password); source.sendSuccess(() -> Component.translatable("message.voicechat.join_successful", Component.literal(group.getName()).withStyle(ChatFormatting.GRAY)), false); return 1; } @@ -277,7 +278,7 @@ private static int help(CommandDispatcher dispatcher, Comman private static boolean checkNoVoicechat(CommandContext commandSource) { try { ServerPlayer player = commandSource.getSource().getPlayerOrException(); - if (Voicechat.SERVER.isCompatible(player)) { + if (Voicechat.SERVER.isCompatible(MinecraftCompatibilityManager.fromServerPlayer(player))) { return false; } commandSource.getSource().sendFailure(Component.literal(Voicechat.TRANSLATIONS.voicechatNeededForCommandMessage.get().formatted(CommonCompatibilityManager.INSTANCE.getModName()))); @@ -290,7 +291,7 @@ private static boolean checkNoVoicechat(CommandContext comma private static boolean checkPermission(CommandSourceStack stack, Permission permission) { try { - return permission.hasPermission(stack.getPlayerOrException()); + return permission.hasPermission(MinecraftCompatibilityManager.fromServerPlayer(stack.getPlayerOrException())); } catch (CommandSyntaxException e) { return stack.hasPermission(stack.getServer().getOperatorUserPermissionLevel()); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/MinecraftCompatibilityManager.java b/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/MinecraftCompatibilityManager.java new file mode 100644 index 000000000..36ade7947 --- /dev/null +++ b/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/MinecraftCompatibilityManager.java @@ -0,0 +1,170 @@ +package de.maxhenkel.voicechat.intercompatibility; + +import com.mojang.brigadier.CommandDispatcher; +import de.maxhenkel.voicechat.BuildConstants; +import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.api.*; +import de.maxhenkel.voicechat.command.VoicechatCommands; +import de.maxhenkel.voicechat.plugins.impl.*; +import io.netty.buffer.ByteBuf; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.locale.Language; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.phys.Vec3; + +import java.util.Timer; +import java.util.TimerTask; +import java.util.function.Consumer; + +public abstract class MinecraftCompatibilityManager extends CommonCompatibilityManager { + + @Override + public void registerCommands() { + onRegisterServerCommands(VoicechatCommands::register); + } + + public abstract void onRegisterServerCommands(Consumer> onRegisterServerCommands); + + @Override + public VoicechatServerApi getServerApi() { + return VoicechatServerApiImpl.INSTANCE; + } + + @Override + public void sendMinecraftPacket(ServerPlayer player, de.maxhenkel.voicechat.voice.common.ResourceLocation id, ByteBuf buffer) { + MinecraftCompatibilityManager.getServerPlayer(player).connection.send(new ClientboundCustomPayloadPacket(new ResourceLocation(id.key(), id.value()), new FriendlyByteBuf(buffer))); + } + + @Override + public void displayClientMessage(ServerPlayer player, String message, boolean overlay) { + MinecraftCompatibilityManager.getServerPlayer(player).displayClientMessage(Component.translatable(message), overlay); + } + + @Override + public void createTimeoutTimer(ServerPlayer player) { + net.minecraft.server.level.ServerPlayer serverPlayer = MinecraftCompatibilityManager.getServerPlayer(player); + Timer timer = new Timer("%s-login-timer".formatted(serverPlayer.getName()), true); + timer.schedule(new TimerTask() { + @Override + public void run() { + timer.cancel(); + timer.purge(); + if (!serverPlayer.server.isRunning()) { + return; + } + if (!serverPlayer.connection.isAcceptingMessages()) { + return; + } + if (!Voicechat.SERVER.isCompatible(player)) { + executeOnMinecraftServer(MinecraftCompatibilityManager.fromServer(serverPlayer.server), () -> { + serverPlayer.connection.disconnect( + Component.literal(Voicechat.TRANSLATIONS.forceVoicechatKickMessage.get().formatted( + CommonCompatibilityManager.INSTANCE.getModName(), + CommonCompatibilityManager.INSTANCE.getModVersion() + ))); + }); + } + } + }, Voicechat.SERVER_CONFIG.loginTimeout.get()); + } + + @Override + public void executeOnMinecraftServer(MinecraftServer server, Runnable runnable) { + MinecraftCompatibilityManager.getServer(server).execute(runnable); + } + + @Override + public void sendIncompatibleMessage(ServerPlayer serverPlayer, int compatibilityVersion) { + Component component; + if (compatibilityVersion <= 6) { + component = Component.literal(Voicechat.TRANSLATIONS.voicechatNotCompatibleMessage.get().formatted(BuildConstants.MOD_COMPATIBLE_VERSION, CommonCompatibilityManager.INSTANCE.getModName())); + } else { + component = Component.translatableWithFallback("message.voicechat.incompatible_version", + "Your voice chat client version is not compatible with the server-side version.\nPlease install version %s of %s.", + Component.literal(BuildConstants.MOD_COMPATIBLE_VERSION).withStyle(ChatFormatting.BOLD), + Component.literal(CommonCompatibilityManager.INSTANCE.getModName()).withStyle(ChatFormatting.BOLD)); + } + MinecraftCompatibilityManager.getServerPlayer(serverPlayer).sendSystemMessage(component); + } + + public static Component getCategoryDisplayName(VolumeCategory category) { + if (category.getNameTranslationKey() != null) { + return Component.translatableWithFallback(category.getNameTranslationKey(), category.getName()); + } + return Component.literal(category.getName()); + } + + public static String getCategorySearchName(VolumeCategory category) { + if (category.getNameTranslationKey() == null) { + return category.getName(); + } + Language lang = Language.getInstance(); + return lang.getOrDefault(category.getNameTranslationKey(), category.getName()); + } + + public static Component getCategoryDisplayDescription(VolumeCategory category) { + if (category.getDescriptionTranslationKey() != null) { + return Component.translatableWithFallback(category.getDescriptionTranslationKey(), category.getDescription()); + } + return category.getDescription() != null ? Component.literal(category.getDescription()) : Component.empty(); + } + + public static ServerLevel fromServerLevel(Object serverLevel) { + if (serverLevel instanceof net.minecraft.server.level.ServerLevel l) { + return new ServerLevelImpl(l); + } else { + throw new IllegalArgumentException("serverLevel is not an instance of ServerLevel"); + } + } + + public static ServerPlayer fromServerPlayer(Object serverPlayer) { + if (serverPlayer instanceof net.minecraft.server.level.ServerPlayer p) { + return new ServerPlayerImpl(p); + } else { + throw new IllegalArgumentException("serverPlayer is not an instance of ServerPlayer"); + } + } + + public static MinecraftServer fromServer(Object minecraftServer) { + if (minecraftServer instanceof net.minecraft.server.MinecraftServer s) { + return new MinecraftServerImpl(s); + } else { + throw new IllegalArgumentException("minecraftServer is not an instance of MinecraftServer"); + } + } + + @Override + public Position createPosition(double x, double y, double z) { + return fromVec3(new Vec3(x,y,z)); + } + + public static Position fromVec3(Object vec3) { + if (vec3 instanceof Vec3 v) { + return new PositionImpl(v); + } else { + throw new IllegalArgumentException("vec3 is not an instance of Vec3"); + } + } + + public static net.minecraft.server.level.ServerPlayer getServerPlayer(ServerPlayer player) { + if (player.getEntity() instanceof net.minecraft.server.level.ServerPlayer serverPlayer) { + return serverPlayer; + } else throw new IllegalArgumentException("player does not wrap ServerPlayer"); + } + + public static net.minecraft.server.MinecraftServer getServer(MinecraftServer server) { + if (server.getMinecraftServer() instanceof net.minecraft.server.MinecraftServer minecraftServer) { + return minecraftServer; + } else throw new IllegalArgumentException("minecraftServer does not wrap MinecraftServer"); + } + + public static Vec3 getVec3(Position position) { + if (position instanceof PositionImpl positionImpl) { + return positionImpl.getPosition(); + } else throw new IllegalArgumentException("position does not wrap Vec3"); + } +} diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/Packet.java b/common/src/main/java/de/maxhenkel/voicechat/net/Packet.java deleted file mode 100644 index dbb56562d..000000000 --- a/common/src/main/java/de/maxhenkel/voicechat/net/Packet.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.maxhenkel.voicechat.net; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; - -public interface Packet> { - - ResourceLocation getIdentifier(); - - T fromBytes(FriendlyByteBuf buf); - - void toBytes(FriendlyByteBuf buf); - -} diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/EntityImpl.java b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/EntityImpl.java index ab4f5e175..c60a5e0a8 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/EntityImpl.java +++ b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/EntityImpl.java @@ -2,7 +2,9 @@ import de.maxhenkel.voicechat.api.Entity; import de.maxhenkel.voicechat.api.Position; -import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; +import de.maxhenkel.voicechat.api.ServerLevel; +import net.minecraft.world.level.Level; import java.util.Objects; import java.util.UUID; @@ -22,16 +24,25 @@ public UUID getUuid() { @Override public Object getEntity() { - return CommonCompatibilityManager.INSTANCE.createRawApiEntity(entity); + return entity; } @Override public Position getPosition() { - return new PositionImpl(entity.position()); + return MinecraftCompatibilityManager.fromVec3(entity.position()); } - public net.minecraft.world.entity.Entity getRealEntity() { - return entity; + @Override + public Position getEyePosition() { + return MinecraftCompatibilityManager.fromVec3(entity.getEyePosition()); + } + + @Override + public ServerLevel getLevel() { + Level level = entity.level(); + if (level instanceof net.minecraft.server.level.ServerLevel serverLevel) + return MinecraftCompatibilityManager.fromServerLevel(serverLevel); + else throw new IllegalStateException("Tried to access getServerLevel() on client!"); } @Override diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/MinecraftServerImpl.java b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/MinecraftServerImpl.java new file mode 100644 index 000000000..f141497ab --- /dev/null +++ b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/MinecraftServerImpl.java @@ -0,0 +1,76 @@ +package de.maxhenkel.voicechat.plugins.impl; + +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import java.util.stream.Collectors; + +public class MinecraftServerImpl implements MinecraftServer { + + protected net.minecraft.server.MinecraftServer server; + + public MinecraftServerImpl(net.minecraft.server.MinecraftServer server) { + this.server = server; + } + + public net.minecraft.server.MinecraftServer getMinecraftServer() { + return server; + } + + @Override + public int getPort() { + return server.getPort(); + } + + @Override + public String getIp() { + return server.getLocalIp(); + } + + @Override + public ServerPlayer getPlayer(UUID playerUUID) { + return MinecraftCompatibilityManager.fromServerPlayer(server.getPlayerList().getPlayer(playerUUID)); + } + + @Override + public List getPlayers() { + return server.getPlayerList().getPlayers().stream().map(MinecraftCompatibilityManager::fromServerPlayer).collect(Collectors.toCollection(ArrayList::new)); + } + + @Override + public boolean isDedicated() { + return server.isDedicatedServer(); + } + + @Override + public boolean usesAuthentication() { + return server.usesAuthentication(); + } + + @Override + public int getOperatorUserPermissionLevel() { + return server.getOperatorUserPermissionLevel(); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + MinecraftServerImpl that = (MinecraftServerImpl) object; + return Objects.equals(server, that.server); + } + + @Override + public int hashCode() { + return server != null ? server.hashCode() : 0; + } +} diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/PlayerImpl.java b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/PlayerImpl.java index 25159cbfe..2eebe76c1 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/PlayerImpl.java +++ b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/PlayerImpl.java @@ -1,7 +1,6 @@ package de.maxhenkel.voicechat.plugins.impl; import de.maxhenkel.voicechat.api.Player; -import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; public class PlayerImpl extends EntityImpl implements Player { @@ -9,13 +8,4 @@ public PlayerImpl(net.minecraft.world.entity.player.Player entity) { super(entity); } - @Override - public Object getPlayer() { - return CommonCompatibilityManager.INSTANCE.createRawApiPlayer(getRealPlayer()); - } - - public net.minecraft.world.entity.player.Player getRealPlayer() { - return (net.minecraft.world.entity.player.Player) entity; - } - } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerLevelImpl.java b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerLevelImpl.java index 24196207e..81fe47f69 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerLevelImpl.java +++ b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerLevelImpl.java @@ -1,9 +1,13 @@ package de.maxhenkel.voicechat.plugins.impl; import de.maxhenkel.voicechat.api.ServerLevel; -import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import de.maxhenkel.voicechat.api.ServerPlayer; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class ServerLevelImpl implements ServerLevel { @@ -14,12 +18,13 @@ public ServerLevelImpl(net.minecraft.server.level.ServerLevel serverLevel) { } @Override - public Object getServerLevel() { - return CommonCompatibilityManager.INSTANCE.createRawApiLevel(serverLevel); + public net.minecraft.server.level.ServerLevel getServerLevel() { + return serverLevel; } - public net.minecraft.server.level.ServerLevel getRawServerLevel() { - return serverLevel; + @Override + public List players() { + return serverLevel.players().stream().map(MinecraftCompatibilityManager::fromServerPlayer).collect(Collectors.toCollection(ArrayList::new)); } @Override diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerPlayerImpl.java b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerPlayerImpl.java index 6b1e723cd..93e048dc1 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerPlayerImpl.java +++ b/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/ServerPlayerImpl.java @@ -1,7 +1,8 @@ package de.maxhenkel.voicechat.plugins.impl; -import de.maxhenkel.voicechat.api.ServerLevel; import de.maxhenkel.voicechat.api.ServerPlayer; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; +import net.minecraft.world.entity.Entity; public class ServerPlayerImpl extends PlayerImpl implements ServerPlayer { @@ -9,12 +10,27 @@ public ServerPlayerImpl(net.minecraft.server.level.ServerPlayer entity) { super(entity); } - public net.minecraft.server.level.ServerPlayer getRealServerPlayer() { - return (net.minecraft.server.level.ServerPlayer) entity; + @Override + public String getName() { + return entity.getName().getString(); + } + + @Override + public ServerPlayer getCameraPlayer() { + Entity camera = ((net.minecraft.server.level.ServerPlayer)entity).getCamera(); + if (camera instanceof net.minecraft.server.level.ServerPlayer serverPlayer) + return MinecraftCompatibilityManager.fromServerPlayer(serverPlayer); + else + return null; + } + + @Override + public boolean isSpectator() { + return entity.isSpectator(); } @Override - public ServerLevel getServerLevel() { - return new ServerLevelImpl((net.minecraft.server.level.ServerLevel) entity.level()); + public boolean hasPermissions(int operatorUserPermissionLevel) { + return entity.hasPermissions(operatorUserPermissionLevel); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/Utils.java b/common/src/main/java/de/maxhenkel/voicechat/voice/common/Utils.java deleted file mode 100644 index dcc85c779..000000000 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/Utils.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.maxhenkel.voicechat.voice.common; - -import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.util.Mth; -import net.minecraft.world.phys.Vec2; - -public class Utils { - - public static void sleep(int ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException ex) { - } - } - - public static float normalizeAngle(float angle) { - angle = angle % 360F; - if (angle <= -180F) { - angle += 360F; - } else if (angle > 180F) { - angle -= 360F; - } - return angle; - } - - public static float angle(Vec2 vec1, Vec2 vec2) { - return (float) Math.toDegrees(Math.atan2(vec1.x * vec2.x + vec1.y * vec2.y, vec1.x * vec2.y - vec1.y * vec2.x)); - } - - private static double magnitude(Vec2 vec1) { - return Math.sqrt(Math.pow(vec1.x, 2) + Math.pow(vec1.y, 2)); - } - - private static float multiply(Vec2 vec1, Vec2 vec2) { - return vec1.x * vec2.x + vec1.y * vec2.y; - } - - private static Vec2 rotate(Vec2 vec, float angle) { - return new Vec2(vec.x * Mth.cos(angle) - vec.y * Mth.sin(angle), vec.x * Mth.sin(angle) + vec.y * Mth.cos(angle)); - } - - public static float getDefaultDistanceServer() { - return Voicechat.SERVER_CONFIG.voiceChatDistance.get().floatValue(); - } - -} diff --git a/common/src/main/resources/assets/voicechat/lang/de_de.json b/common/src/main/resources/assets/voicechat/lang/de_de.json index c54d9c809..166e8bbe1 100644 --- a/common/src/main/resources/assets/voicechat/lang/de_de.json +++ b/common/src/main/resources/assets/voicechat/lang/de_de.json @@ -22,7 +22,11 @@ "message.voicechat.settings": "Einstellungen", "message.voicechat.group": "Gruppe", "message.voicechat.voice_chat_volume": "Sprachchat Lautstärke: %s", + "message.voicechat.gain.auto": "Auto", + "message.voicechat.gain.manual": "Manuell", + "message.voicechat.gain.manual.warning": "Bitte lassen Sie die automatische Mikrofonverstärkung aktiviert, um eine gleichbleibende Lautstärke für alle Zuhörer zu gewährleisten.", "message.voicechat.microphone_gain": "Mikrofonverstärkung: %s dB", + "message.voicechat.microphone_gain.warning": "Eine Verstärkung von mehr als %s dB kann zu Audioverzerrungen und anderen Problemen führen!", "message.voicechat.mic_test_unavailable": "Mikrofontest nicht verfügbar", "message.voicechat.mic_test.disabled": "Klicke um den Mikrofontest zu aktivieren", "message.voicechat.mic_test.enabled": "Klicke um den Mikrofontest zu deaktivieren", @@ -40,6 +44,7 @@ "message.voicechat.default_microphone": "Systemstandard", "message.voicechat.no_speaker": "Kein Lautsprecher verfügbar", "message.voicechat.default_speaker": "Systemstandard", + "message.voicechat.test_speaker": "Klicke um einen Testton abzuspielen.", "message.voicechat.select_microphone": "Mikrofon auswählen", "message.voicechat.select_speaker": "Lautsprecher auswählen", "message.voicechat.back": "Zurück", @@ -133,6 +138,7 @@ "message.voicechat.audio_type.off": "Aus", "message.voicechat.invite_player": "%s in Ihre Gruppe einladen", "message.voicechat.press_to_reassign_key": "Klicke um die zugewiesene Taste neu zu setzen.", + "message.voicechat.native_error": "Einige Module konnten nicht geladen werden - Ihr Betriebssystem wird möglicherweise nicht unterstützt.", "message.voicechat.set_up": "Drücke %s um zu konfigurieren", "message.voicechat.onboarding.reset": "Einrichtungsstatus zurückgesetzt", "message.voicechat.onboarding.next": "Weiter", @@ -173,6 +179,7 @@ "cloth_config.voicechat.category.general": "Allgemein", "cloth_config.voicechat.category.audio": "Audio", "cloth_config.voicechat.category.hud_icons": "HUD Symbole", + "cloth_config.voicechat.category.group_chat_icons": "Gruppensymbole", "cloth_config.voicechat.category.ingame_menu": "Sonstiges", "cloth_config.voicechat.config.recording_destination": "Aufnahmepfad", "cloth_config.voicechat.config.run_local_server": "In Einzelspieler/LAN Welten ausführen", @@ -182,8 +189,11 @@ "cloth_config.voicechat.config.freecam_mode.player": "Spieler", "cloth_config.voicechat.config.mute_on_join": "Stummschalten beim betreten", "cloth_config.voicechat.config.audio_packet_threshold": "Audio Paket Schwellenwert", - "cloth_config.voicechat.config.voice_deactivation_delay": "Verzögerung der Deaktivierung", + "cloth_config.voicechat.config.voice_deactivation_delay": "Deaktivierungsverzögerung für Sprachaktivierung", + "cloth_config.voicechat.config.ptt_deactivation_delay": "Deaktivierungsverzögerung für drücken zum sprechen", "cloth_config.voicechat.config.output_buffer_size": "Größe des Ausgabepuffers", + "cloth_config.voicechat.config.show_nametag_icons": "Sprachchat Namenssymbole anzeigen", + "cloth_config.voicechat.config.show_hud_icons": "Sprachchat HUD Symbole anzeigen", "cloth_config.voicechat.config.hud_icon_scale": "HUD Symbol Skalierung", "cloth_config.voicechat.config.hud_icon_pos_x": "HUD Symbol X Position", "cloth_config.voicechat.config.hud_icon_pos_y": "HUD Symbol Y Position", diff --git a/common/src/main/resources/assets/voicechat/lang/en_us.json b/common/src/main/resources/assets/voicechat/lang/en_us.json index 443af7160..518c3144e 100644 --- a/common/src/main/resources/assets/voicechat/lang/en_us.json +++ b/common/src/main/resources/assets/voicechat/lang/en_us.json @@ -183,6 +183,7 @@ "cloth_config.voicechat.category.general": "General", "cloth_config.voicechat.category.audio": "Audio", "cloth_config.voicechat.category.hud_icons": "HUD Icons", + "cloth_config.voicechat.category.group_chat_icons": "Group Chat Icons", "cloth_config.voicechat.category.ingame_menu": "In-Game Menu", "cloth_config.voicechat.config.recording_destination": "Recording destination", "cloth_config.voicechat.config.recording_destination.description": "The location where recordings should be saved.\nLeave blank to use the default location.", diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 000000000..882dea6a4 --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,41 @@ +apply plugin: 'java' +apply plugin: 'com.gradleup.shadow' + +apply from: "https://raw.githubusercontent.com/henkelmax/mod-gradle-scripts/${mod_gradle_script_version}/mod.gradle" + +java { + toolchain.languageVersion = JavaLanguageVersion.of(17) +} + +repositories { + mavenCentral() + + maven { url = 'https://maven.shedaniel.me/' } + maven { url = 'https://maven.maxhenkel.de/repository/public' } + maven { url = 'https://maven.fabricmc.net/' } +} + +dependencies { + implementation 'com.google.code.findbugs:jsr305:3.0.2' + implementation 'io.netty:netty-buffer:4.2.5.Final' + implementation 'org.apache.logging.log4j:log4j-api:2.19.0' + implementation 'org.apache.logging.log4j:log4j-core:2.19.0' + implementation "net.java.dev.jna:jna:5.14.0" + + implementation "de.maxhenkel.configbuilder:configbuilder:${configbuilder_version}" + implementation "de.maxhenkel.opus4j:opus4j:${opus4j_version}" + implementation "org.concentus:Concentus:${concentus_version}" + implementation "de.maxhenkel.lame4j:lame4j:${lame4j_version}" +} + +sourceSets { + template { + java { + srcDir 'src/template/java' + } + } + main { + compileClasspath += sourceSets.template.output + runtimeClasspath += sourceSets.template.output + } +} diff --git a/core/gradle.properties b/core/gradle.properties new file mode 100644 index 000000000..8e2ea5633 --- /dev/null +++ b/core/gradle.properties @@ -0,0 +1,7 @@ +mod_loader=none + +included_projects=:api + +enable_curseforge_upload=false +enable_modrinth_upload=false +enable_mod_update=false diff --git a/common/src/main/java/de/maxhenkel/voicechat/Voicechat.java b/core/src/main/java/de/maxhenkel/voicechat/Voicechat.java similarity index 91% rename from common/src/main/java/de/maxhenkel/voicechat/Voicechat.java rename to core/src/main/java/de/maxhenkel/voicechat/Voicechat.java index 23c07466a..231818ae9 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/Voicechat.java +++ b/core/src/main/java/de/maxhenkel/voicechat/Voicechat.java @@ -1,7 +1,6 @@ package de.maxhenkel.voicechat; import de.maxhenkel.configbuilder.ConfigBuilder; -import de.maxhenkel.voicechat.command.VoicechatCommands; import de.maxhenkel.voicechat.config.ServerConfig; import de.maxhenkel.voicechat.config.Translations; import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; @@ -37,17 +36,13 @@ public void initialize() { CommonCompatibilityManager.INSTANCE.getNetManager().init(); SERVER = new ServerVoiceEvents(); initPlugins(); - registerCommands(); + CommonCompatibilityManager.INSTANCE.registerCommands(); } protected void initPlugins() { PluginManager.instance().init(); } - protected void registerCommands() { - CommonCompatibilityManager.INSTANCE.onRegisterServerCommands(VoicechatCommands::register); - } - public void initializeConfigs() { SERVER_CONFIG = ConfigBuilder.builder(ServerConfig::new).path(getVoicechatConfigFolderInternal().resolve("voicechat-server.properties")).build(); TRANSLATIONS = ConfigBuilder.builder(Translations::new).path(getVoicechatConfigFolderInternal().resolve("translations.properties")).build(); diff --git a/common/src/main/java/de/maxhenkel/voicechat/config/ServerConfig.java b/core/src/main/java/de/maxhenkel/voicechat/config/ServerConfig.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/config/ServerConfig.java rename to core/src/main/java/de/maxhenkel/voicechat/config/ServerConfig.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/config/Translations.java b/core/src/main/java/de/maxhenkel/voicechat/config/Translations.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/config/Translations.java rename to core/src/main/java/de/maxhenkel/voicechat/config/Translations.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/debug/CooldownTimer.java b/core/src/main/java/de/maxhenkel/voicechat/debug/CooldownTimer.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/debug/CooldownTimer.java rename to core/src/main/java/de/maxhenkel/voicechat/debug/CooldownTimer.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/debug/PingHandler.java b/core/src/main/java/de/maxhenkel/voicechat/debug/PingHandler.java similarity index 72% rename from common/src/main/java/de/maxhenkel/voicechat/debug/PingHandler.java rename to core/src/main/java/de/maxhenkel/voicechat/debug/PingHandler.java index dd628f9c7..362d24dd1 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/debug/PingHandler.java +++ b/core/src/main/java/de/maxhenkel/voicechat/debug/PingHandler.java @@ -1,9 +1,10 @@ package de.maxhenkel.voicechat.debug; import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.voice.common.BufferUtils; import de.maxhenkel.voicechat.voice.server.Server; +import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import net.minecraft.network.FriendlyByteBuf; import java.net.SocketAddress; import java.util.UUID; @@ -12,7 +13,7 @@ public class PingHandler { public static final UUID PING_V1 = UUID.fromString("58bc9ae9-c7a8-45e4-a11c-efbb67199425"); - public static boolean onPacket(Server server, SocketAddress socketAddress, UUID playerID, FriendlyByteBuf buf) { + public static boolean onPacket(Server server, SocketAddress socketAddress, UUID playerID, ByteBuf buf) { if (!Voicechat.SERVER_CONFIG.allowPings.get()) { return false; } @@ -20,15 +21,15 @@ public static boolean onPacket(Server server, SocketAddress socketAddress, UUID return false; } try { - byte[] payload = buf.readByteArray(); - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.wrappedBuffer(payload)); - UUID id = buffer.readUUID(); + byte[] payload = BufferUtils.readByteArray(buf); + ByteBuf buffer = Unpooled.wrappedBuffer(payload); + UUID id = BufferUtils.readUUID(buffer); long timestamp = buffer.readLong(); Voicechat.LOGGER.debug("Received ping {} from {}", id, socketAddress); - FriendlyByteBuf responseBuffer = new FriendlyByteBuf(Unpooled.buffer(24)); + ByteBuf responseBuffer = Unpooled.buffer(24); - responseBuffer.writeUUID(id); + BufferUtils.writeUUID(responseBuffer, id); responseBuffer.writeLong(timestamp); byte[] response = new byte[responseBuffer.readableBytes()]; diff --git a/common/src/main/java/de/maxhenkel/voicechat/debug/VoicechatUncaughtExceptionHandler.java b/core/src/main/java/de/maxhenkel/voicechat/debug/VoicechatUncaughtExceptionHandler.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/debug/VoicechatUncaughtExceptionHandler.java rename to core/src/main/java/de/maxhenkel/voicechat/debug/VoicechatUncaughtExceptionHandler.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager.java b/core/src/main/java/de/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager.java similarity index 68% rename from common/src/main/java/de/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager.java rename to core/src/main/java/de/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager.java index 950ff085c..71fafa80b 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/intercompatibility/CommonCompatibilityManager.java @@ -1,18 +1,11 @@ package de.maxhenkel.voicechat.intercompatibility; -import com.mojang.brigadier.CommandDispatcher; -import de.maxhenkel.voicechat.api.VoicechatPlugin; -import de.maxhenkel.voicechat.api.VoicechatServerApi; +import de.maxhenkel.voicechat.api.*; import de.maxhenkel.voicechat.net.NetManager; import de.maxhenkel.voicechat.permission.PermissionManager; -import de.maxhenkel.voicechat.plugins.impl.VoicechatServerApiImpl; import de.maxhenkel.voicechat.service.Service; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; +import io.netty.buffer.ByteBuf; import java.nio.file.Path; import java.util.List; @@ -60,7 +53,7 @@ public abstract class CommonCompatibilityManager { public abstract void onPlayerCompatibilityCheckSucceeded(Consumer onPlayerCompatibilityCheckSucceeded); - public abstract void onRegisterServerCommands(Consumer> onRegisterServerCommands); + public abstract void registerCommands(); public abstract NetManager getNetManager(); @@ -74,26 +67,19 @@ public abstract class CommonCompatibilityManager { public abstract PermissionManager createPermissionManager(); - public VoicechatServerApi getServerApi() { - return VoicechatServerApiImpl.INSTANCE; - } + public abstract VoicechatServerApi getServerApi(); - public Object createRawApiEntity(Entity entity) { - return entity; - } + public abstract boolean canSee(ServerPlayer player, ServerPlayer other); - public Object createRawApiPlayer(Player player) { - return player; - } + public abstract void executeOnMinecraftServer(MinecraftServer server, Runnable runnable); - public Object createRawApiLevel(ServerLevel level) { - return level; - } + public abstract void sendMinecraftPacket(ServerPlayer player, ResourceLocation id, ByteBuf buffer); - public abstract boolean canSee(ServerPlayer player, ServerPlayer other); + public abstract void displayClientMessage(ServerPlayer player, String message, boolean overlay); + + public abstract void createTimeoutTimer(ServerPlayer player); - public void execute(MinecraftServer server, Runnable runnable) { - server.execute(runnable); - } + public abstract void sendIncompatibleMessage(ServerPlayer serverPlayer, int compatibilityVersion); + public abstract Position createPosition(double x, double y, double z); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/CrossSideManager.java b/core/src/main/java/de/maxhenkel/voicechat/intercompatibility/CrossSideManager.java similarity index 95% rename from common/src/main/java/de/maxhenkel/voicechat/intercompatibility/CrossSideManager.java rename to core/src/main/java/de/maxhenkel/voicechat/intercompatibility/CrossSideManager.java index f8d4f3a62..399f641c4 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/CrossSideManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/intercompatibility/CrossSideManager.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.intercompatibility; -import net.minecraft.server.MinecraftServer; +import de.maxhenkel.voicechat.api.MinecraftServer; public abstract class CrossSideManager { diff --git a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/DedicatedServerCrossSideManager.java b/core/src/main/java/de/maxhenkel/voicechat/intercompatibility/DedicatedServerCrossSideManager.java similarity index 90% rename from common/src/main/java/de/maxhenkel/voicechat/intercompatibility/DedicatedServerCrossSideManager.java rename to core/src/main/java/de/maxhenkel/voicechat/intercompatibility/DedicatedServerCrossSideManager.java index f6c4624a6..d1cded57f 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/intercompatibility/DedicatedServerCrossSideManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/intercompatibility/DedicatedServerCrossSideManager.java @@ -1,7 +1,7 @@ package de.maxhenkel.voicechat.intercompatibility; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.server.MinecraftServer; +import de.maxhenkel.voicechat.api.MinecraftServer; public class DedicatedServerCrossSideManager extends CrossSideManager { diff --git a/common/src/main/java/de/maxhenkel/voicechat/logging/Log4JVoicechatLogger.java b/core/src/main/java/de/maxhenkel/voicechat/logging/Log4JVoicechatLogger.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/logging/Log4JVoicechatLogger.java rename to core/src/main/java/de/maxhenkel/voicechat/logging/Log4JVoicechatLogger.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/logging/LogLevel.java b/core/src/main/java/de/maxhenkel/voicechat/logging/LogLevel.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/logging/LogLevel.java rename to core/src/main/java/de/maxhenkel/voicechat/logging/LogLevel.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/logging/VoicechatLogger.java b/core/src/main/java/de/maxhenkel/voicechat/logging/VoicechatLogger.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/logging/VoicechatLogger.java rename to core/src/main/java/de/maxhenkel/voicechat/logging/VoicechatLogger.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/macos/VersionCheck.java b/core/src/main/java/de/maxhenkel/voicechat/macos/VersionCheck.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/macos/VersionCheck.java rename to core/src/main/java/de/maxhenkel/voicechat/macos/VersionCheck.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/natives/LameManager.java b/core/src/main/java/de/maxhenkel/voicechat/natives/LameManager.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/natives/LameManager.java rename to core/src/main/java/de/maxhenkel/voicechat/natives/LameManager.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/natives/NativeUtils.java b/core/src/main/java/de/maxhenkel/voicechat/natives/NativeUtils.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/natives/NativeUtils.java rename to core/src/main/java/de/maxhenkel/voicechat/natives/NativeUtils.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/natives/NativeValidator.java b/core/src/main/java/de/maxhenkel/voicechat/natives/NativeValidator.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/natives/NativeValidator.java rename to core/src/main/java/de/maxhenkel/voicechat/natives/NativeValidator.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/natives/OpusManager.java b/core/src/main/java/de/maxhenkel/voicechat/natives/OpusManager.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/natives/OpusManager.java rename to core/src/main/java/de/maxhenkel/voicechat/natives/OpusManager.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/AddCategoryPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/AddCategoryPacket.java similarity index 80% rename from common/src/main/java/de/maxhenkel/voicechat/net/AddCategoryPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/AddCategoryPacket.java index 9c344a7bf..99add8089 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/AddCategoryPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/AddCategoryPacket.java @@ -2,8 +2,8 @@ import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.plugins.impl.VolumeCategoryImpl; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class AddCategoryPacket implements Packet { @@ -29,13 +29,13 @@ public ResourceLocation getIdentifier() { } @Override - public AddCategoryPacket fromBytes(FriendlyByteBuf buf) { + public AddCategoryPacket fromBytes(ByteBuf buf) { category = VolumeCategoryImpl.fromBytes(buf); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { category.toBytes(buf); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/AddGroupPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/AddGroupPacket.java similarity index 79% rename from common/src/main/java/de/maxhenkel/voicechat/net/AddGroupPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/AddGroupPacket.java index a2d03dd54..b312aa153 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/AddGroupPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/AddGroupPacket.java @@ -2,8 +2,8 @@ import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.voice.common.ClientGroup; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class AddGroupPacket implements Packet { @@ -29,13 +29,13 @@ public ResourceLocation getIdentifier() { } @Override - public AddGroupPacket fromBytes(FriendlyByteBuf buf) { + public AddGroupPacket fromBytes(ByteBuf buf) { group = ClientGroup.fromBytes(buf); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { group.toBytes(buf); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/Channel.java b/core/src/main/java/de/maxhenkel/voicechat/net/Channel.java similarity index 68% rename from common/src/main/java/de/maxhenkel/voicechat/net/Channel.java rename to core/src/main/java/de/maxhenkel/voicechat/net/Channel.java index 77c49dc70..93b13f41d 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/Channel.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/Channel.java @@ -1,9 +1,8 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import javax.annotation.Nullable; @@ -20,8 +19,8 @@ public void setServerListener(NetManager.ServerReceiver packetReceiver) { serverListener = packetReceiver; } - public void onServerPacket(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl handler, T packet) { - CommonCompatibilityManager.INSTANCE.execute(server, () -> { + public void onServerPacket(MinecraftServer server, ServerPlayer player, Object handler, T packet) { + CommonCompatibilityManager.INSTANCE.executeOnMinecraftServer(server, () -> { if (serverListener != null) { serverListener.onPacket(server, player, handler, packet); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/CreateGroupPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/CreateGroupPacket.java similarity index 75% rename from common/src/main/java/de/maxhenkel/voicechat/net/CreateGroupPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/CreateGroupPacket.java index adf1dafc5..1ac2f738c 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/CreateGroupPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/CreateGroupPacket.java @@ -3,8 +3,9 @@ import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.api.Group; import de.maxhenkel.voicechat.plugins.impl.GroupImpl; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; import javax.annotation.Nullable; @@ -46,22 +47,22 @@ public ResourceLocation getIdentifier() { } @Override - public CreateGroupPacket fromBytes(FriendlyByteBuf buf) { - name = buf.readUtf(512); + public CreateGroupPacket fromBytes(ByteBuf buf) { + name = BufferUtils.readUtf(buf, 512); password = null; if (buf.readBoolean()) { - password = buf.readUtf(512); + password = BufferUtils.readUtf(buf, 512); } type = GroupImpl.TypeImpl.fromInt(buf.readShort()); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUtf(name, 512); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUtf(buf, name, 512); buf.writeBoolean(password != null); if (password != null) { - buf.writeUtf(password, 512); + BufferUtils.writeUtf(buf, password, 512); } buf.writeShort(GroupImpl.TypeImpl.toInt(type)); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/JoinGroupPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/JoinGroupPacket.java similarity index 69% rename from common/src/main/java/de/maxhenkel/voicechat/net/JoinGroupPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/JoinGroupPacket.java index eb69d22d5..6b6908cf3 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/JoinGroupPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/JoinGroupPacket.java @@ -1,8 +1,9 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; import javax.annotation.Nullable; import java.util.UUID; @@ -39,20 +40,20 @@ public ResourceLocation getIdentifier() { } @Override - public JoinGroupPacket fromBytes(FriendlyByteBuf buf) { - group = buf.readUUID(); + public JoinGroupPacket fromBytes(ByteBuf buf) { + group = BufferUtils.readUUID(buf); if (buf.readBoolean()) { - password = buf.readUtf(512); + password = BufferUtils.readUtf(buf, 512); } return this; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(group); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, group); buf.writeBoolean(password != null); if (password != null) { - buf.writeUtf(password, 512); + BufferUtils.writeUtf(buf, password, 512); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/JoinedGroupPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/JoinedGroupPacket.java similarity index 76% rename from common/src/main/java/de/maxhenkel/voicechat/net/JoinedGroupPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/JoinedGroupPacket.java index 0cf302fe2..dcd0a1e13 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/JoinedGroupPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/JoinedGroupPacket.java @@ -1,8 +1,9 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; import javax.annotation.Nullable; import java.util.UUID; @@ -39,19 +40,19 @@ public ResourceLocation getIdentifier() { } @Override - public JoinedGroupPacket fromBytes(FriendlyByteBuf buf) { + public JoinedGroupPacket fromBytes(ByteBuf buf) { if (buf.readBoolean()) { - group = buf.readUUID(); + group = BufferUtils.readUUID(buf); } wrongPassword = buf.readBoolean(); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { buf.writeBoolean(group != null); if (group != null) { - buf.writeUUID(group); + BufferUtils.writeUUID(buf, group); } buf.writeBoolean(wrongPassword); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/LeaveGroupPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/LeaveGroupPacket.java similarity index 69% rename from common/src/main/java/de/maxhenkel/voicechat/net/LeaveGroupPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/LeaveGroupPacket.java index c3d0cffbb..a9c946d63 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/LeaveGroupPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/LeaveGroupPacket.java @@ -1,8 +1,8 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class LeaveGroupPacket implements Packet { @@ -18,12 +18,12 @@ public ResourceLocation getIdentifier() { } @Override - public LeaveGroupPacket fromBytes(FriendlyByteBuf buf) { + public LeaveGroupPacket fromBytes(ByteBuf buf) { return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/NetManager.java b/core/src/main/java/de/maxhenkel/voicechat/net/NetManager.java similarity index 83% rename from common/src/main/java/de/maxhenkel/voicechat/net/NetManager.java rename to core/src/main/java/de/maxhenkel/voicechat/net/NetManager.java index 2d5dfe5d0..3a4ce8115 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/NetManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/NetManager.java @@ -2,11 +2,10 @@ import de.maxhenkel.voicechat.Voicechat; import io.netty.buffer.Unpooled; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; +import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; public abstract class NetManager { @@ -48,13 +47,13 @@ public static void sendToClient(ServerPlayer player, Packet packet) { if (!Voicechat.SERVER.isCompatible(player)) { return; } - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()); + ByteBuf buffer = Unpooled.buffer(); packet.toBytes(buffer); - player.connection.send(new ClientboundCustomPayloadPacket(packet.getIdentifier(), buffer)); + CommonCompatibilityManager.INSTANCE.sendMinecraftPacket(player, packet.getIdentifier(), buffer); } public interface ServerReceiver> { - void onPacket(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl handler, T packet); + void onPacket(MinecraftServer server, ServerPlayer player, Object handler, T packet); } } diff --git a/core/src/main/java/de/maxhenkel/voicechat/net/Packet.java b/core/src/main/java/de/maxhenkel/voicechat/net/Packet.java new file mode 100644 index 000000000..ff184e502 --- /dev/null +++ b/core/src/main/java/de/maxhenkel/voicechat/net/Packet.java @@ -0,0 +1,14 @@ +package de.maxhenkel.voicechat.net; + +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; + +public interface Packet> { + + ResourceLocation getIdentifier(); + + T fromBytes(ByteBuf buf); + + void toBytes(ByteBuf buf); + +} diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/PlayerStatePacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/PlayerStatePacket.java similarity index 79% rename from common/src/main/java/de/maxhenkel/voicechat/net/PlayerStatePacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/PlayerStatePacket.java index bac678e55..5dab40167 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/PlayerStatePacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/PlayerStatePacket.java @@ -2,8 +2,8 @@ import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.voice.common.PlayerState; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class PlayerStatePacket implements Packet { @@ -29,13 +29,13 @@ public ResourceLocation getIdentifier() { } @Override - public PlayerStatePacket fromBytes(FriendlyByteBuf buf) { + public PlayerStatePacket fromBytes(ByteBuf buf) { playerState = PlayerState.fromBytes(buf); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { playerState.toBytes(buf); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/PlayerStatesPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/PlayerStatesPacket.java similarity index 85% rename from common/src/main/java/de/maxhenkel/voicechat/net/PlayerStatesPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/PlayerStatesPacket.java index 154827d95..56e119bd8 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/PlayerStatesPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/PlayerStatesPacket.java @@ -2,8 +2,8 @@ import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.voice.common.PlayerState; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; import java.util.*; @@ -31,7 +31,7 @@ public ResourceLocation getIdentifier() { } @Override - public PlayerStatesPacket fromBytes(FriendlyByteBuf buf) { + public PlayerStatesPacket fromBytes(ByteBuf buf) { int count = buf.readInt(); playerStates = new ArrayList<>(count); for (int i = 0; i < count; i++) { @@ -43,7 +43,7 @@ public PlayerStatesPacket fromBytes(FriendlyByteBuf buf) { } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { buf.writeInt(playerStates.size()); for (PlayerState state : playerStates) { state.toBytes(buf); diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/RemoveCategoryPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/RemoveCategoryPacket.java similarity index 66% rename from common/src/main/java/de/maxhenkel/voicechat/net/RemoveCategoryPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/RemoveCategoryPacket.java index d131c5532..eca04f991 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/RemoveCategoryPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/RemoveCategoryPacket.java @@ -1,8 +1,9 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class RemoveCategoryPacket implements Packet { @@ -28,14 +29,14 @@ public ResourceLocation getIdentifier() { } @Override - public RemoveCategoryPacket fromBytes(FriendlyByteBuf buf) { - categoryId = buf.readUtf(16); + public RemoveCategoryPacket fromBytes(ByteBuf buf) { + categoryId = BufferUtils.readUtf(buf, 16); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUtf(categoryId, 16); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUtf(buf, categoryId, 16); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/RemoveGroupPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/RemoveGroupPacket.java similarity index 66% rename from common/src/main/java/de/maxhenkel/voicechat/net/RemoveGroupPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/RemoveGroupPacket.java index 459cbb19f..7d75deef2 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/RemoveGroupPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/RemoveGroupPacket.java @@ -1,8 +1,9 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; import java.util.UUID; @@ -30,14 +31,14 @@ public ResourceLocation getIdentifier() { } @Override - public RemoveGroupPacket fromBytes(FriendlyByteBuf buf) { - groupId = buf.readUUID(); + public RemoveGroupPacket fromBytes(ByteBuf buf) { + groupId = BufferUtils.readUUID(buf); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(groupId); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, groupId); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/RemovePlayerStatePacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/RemovePlayerStatePacket.java similarity index 67% rename from common/src/main/java/de/maxhenkel/voicechat/net/RemovePlayerStatePacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/RemovePlayerStatePacket.java index cda89886a..97e1c9cde 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/RemovePlayerStatePacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/RemovePlayerStatePacket.java @@ -1,8 +1,9 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; import java.util.UUID; @@ -30,14 +31,14 @@ public ResourceLocation getIdentifier() { } @Override - public RemovePlayerStatePacket fromBytes(FriendlyByteBuf buf) { - id = buf.readUUID(); + public RemovePlayerStatePacket fromBytes(ByteBuf buf) { + id = BufferUtils.readUUID(buf); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(id); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, id); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/RequestSecretPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/RequestSecretPacket.java similarity index 79% rename from common/src/main/java/de/maxhenkel/voicechat/net/RequestSecretPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/RequestSecretPacket.java index a1ba135fd..25de77fca 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/RequestSecretPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/RequestSecretPacket.java @@ -1,8 +1,8 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class RequestSecretPacket implements Packet { @@ -28,13 +28,13 @@ public ResourceLocation getIdentifier() { } @Override - public RequestSecretPacket fromBytes(FriendlyByteBuf buf) { + public RequestSecretPacket fromBytes(ByteBuf buf) { compatibilityVersion = buf.readInt(); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { buf.writeInt(compatibilityVersion); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/SecretPacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/SecretPacket.java similarity index 84% rename from common/src/main/java/de/maxhenkel/voicechat/net/SecretPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/SecretPacket.java index 905018740..f9149c2a8 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/SecretPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/SecretPacket.java @@ -4,9 +4,10 @@ import de.maxhenkel.voicechat.config.ServerConfig; import de.maxhenkel.voicechat.plugins.PluginManager; import de.maxhenkel.voicechat.voice.common.Secret; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; +import de.maxhenkel.voicechat.api.ServerPlayer; import java.util.UUID; @@ -32,7 +33,7 @@ public SecretPacket() { public SecretPacket(ServerPlayer player, Secret secret, int port, ServerConfig serverConfig) { this.secret = secret; this.serverPort = port; - this.playerUUID = player.getUUID(); + this.playerUUID = player.getUuid(); this.codec = serverConfig.voiceChatCodec.get(); this.mtuSize = serverConfig.voiceChatMtuSize.get(); this.voiceChatDistance = serverConfig.voiceChatDistance.get(); @@ -88,31 +89,31 @@ public boolean allowRecording() { } @Override - public SecretPacket fromBytes(FriendlyByteBuf buf) { + public SecretPacket fromBytes(ByteBuf buf) { secret = Secret.fromBytes(buf); serverPort = buf.readInt(); - playerUUID = buf.readUUID(); + playerUUID = BufferUtils.readUUID(buf); codec = ServerConfig.Codec.values()[buf.readByte()]; mtuSize = buf.readInt(); voiceChatDistance = buf.readDouble(); keepAlive = buf.readInt(); groupsEnabled = buf.readBoolean(); - voiceHost = buf.readUtf(32767); + voiceHost = BufferUtils.readUtf(buf); allowRecording = buf.readBoolean(); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { secret.toBytes(buf); buf.writeInt(serverPort); - buf.writeUUID(playerUUID); + BufferUtils.writeUUID(buf, playerUUID); buf.writeByte(codec.ordinal()); buf.writeInt(mtuSize); buf.writeDouble(voiceChatDistance); buf.writeInt(keepAlive); buf.writeBoolean(groupsEnabled); - buf.writeUtf(voiceHost); + BufferUtils.writeUtf(buf, voiceHost); buf.writeBoolean(allowRecording); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/ServerChannel.java b/core/src/main/java/de/maxhenkel/voicechat/net/ServerChannel.java similarity index 75% rename from common/src/main/java/de/maxhenkel/voicechat/net/ServerChannel.java rename to core/src/main/java/de/maxhenkel/voicechat/net/ServerChannel.java index ceb6ca670..fbcb6548d 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/ServerChannel.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/ServerChannel.java @@ -1,8 +1,7 @@ package de.maxhenkel.voicechat.net; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import java.util.ArrayList; import java.util.List; @@ -19,7 +18,7 @@ public void registerServerListener(NetManager.ServerReceiver packetReceiver) listeners.add(packetReceiver); } - public void onPacket(MinecraftServer server, ServerPlayer player, ServerGamePacketListenerImpl handler, T packet) { + public void onPacket(MinecraftServer server, ServerPlayer player, Object handler, T packet) { listeners.forEach(receiver -> receiver.onPacket(server, player, handler, packet)); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/net/UpdateStatePacket.java b/core/src/main/java/de/maxhenkel/voicechat/net/UpdateStatePacket.java similarity index 78% rename from common/src/main/java/de/maxhenkel/voicechat/net/UpdateStatePacket.java rename to core/src/main/java/de/maxhenkel/voicechat/net/UpdateStatePacket.java index 79bd269cb..d587d5a52 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/net/UpdateStatePacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/net/UpdateStatePacket.java @@ -1,8 +1,8 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.voice.common.ResourceLocation; public class UpdateStatePacket implements Packet { @@ -28,13 +28,13 @@ public ResourceLocation getIdentifier() { } @Override - public UpdateStatePacket fromBytes(FriendlyByteBuf buf) { + public UpdateStatePacket fromBytes(ByteBuf buf) { disabled = buf.readBoolean(); return this; } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { buf.writeBoolean(disabled); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/permission/Permission.java b/core/src/main/java/de/maxhenkel/voicechat/permission/Permission.java similarity index 77% rename from common/src/main/java/de/maxhenkel/voicechat/permission/Permission.java rename to core/src/main/java/de/maxhenkel/voicechat/permission/Permission.java index e2b4b301b..8d3d754d3 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/permission/Permission.java +++ b/core/src/main/java/de/maxhenkel/voicechat/permission/Permission.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.permission; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.ServerPlayer; public interface Permission { diff --git a/common/src/main/java/de/maxhenkel/voicechat/permission/PermissionManager.java b/core/src/main/java/de/maxhenkel/voicechat/permission/PermissionManager.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/permission/PermissionManager.java rename to core/src/main/java/de/maxhenkel/voicechat/permission/PermissionManager.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/permission/PermissionType.java b/core/src/main/java/de/maxhenkel/voicechat/permission/PermissionType.java similarity index 69% rename from common/src/main/java/de/maxhenkel/voicechat/permission/PermissionType.java rename to core/src/main/java/de/maxhenkel/voicechat/permission/PermissionType.java index e0b5eb223..bbf8b9b2b 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/permission/PermissionType.java +++ b/core/src/main/java/de/maxhenkel/voicechat/permission/PermissionType.java @@ -1,6 +1,7 @@ package de.maxhenkel.voicechat.permission; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.api.ServerPlayer; import javax.annotation.Nullable; @@ -12,7 +13,7 @@ boolean hasPermission(@Nullable ServerPlayer player) { return switch (this) { case EVERYONE -> true; case NOONE -> false; - case OPS -> player != null && player.hasPermissions(player.server.getOperatorUserPermissionLevel()); + case OPS -> player != null && player.hasPermissions(Voicechat.SERVER.getServer().getServer().getOperatorUserPermissionLevel()); }; } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/CategoryManager.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/CategoryManager.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/CategoryManager.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/CategoryManager.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/EventBuilder.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/EventBuilder.java similarity index 56% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/EventBuilder.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/EventBuilder.java index 0891f2146..1edb76ff9 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/EventBuilder.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/EventBuilder.java @@ -1,31 +1,33 @@ package de.maxhenkel.voicechat.plugins; import de.maxhenkel.voicechat.api.events.Event; -import net.minecraft.util.Tuple; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.Consumer; import java.util.stream.Collectors; public class EventBuilder { - private final Map, List>>> events; + private final Map, List> events; private EventBuilder() { events = new HashMap<>(); } public EventBuilder addEvent(Class eventClass, Consumer event, int priority) { - List>> eventList = this.events.getOrDefault(eventClass, new ArrayList<>()); - eventList.add(new Tuple<>(priority, event)); + List eventList = this.events.getOrDefault(eventClass, new ArrayList<>()); + eventList.add(new HandlerEntry(priority, event)); this.events.put(eventClass, eventList); return this; } public Map, List>> build() { Map, List>> result = new HashMap<>(); - for (Map.Entry, List>>> entry : events.entrySet()) { - result.put(entry.getKey(), entry.getValue().stream().sorted((o1, o2) -> Integer.compare(o2.getA(), o1.getA())).map(Tuple::getB).collect(Collectors.toList())); + for (Map.Entry, List> entry : events.entrySet()) { + result.put(entry.getKey(), entry.getValue().stream().sorted((o1, o2) -> Integer.compare(o2.priority, o1.priority)).map(HandlerEntry::handler).collect(Collectors.toList())); } return result; } @@ -34,4 +36,5 @@ public static EventBuilder create() { return new EventBuilder(); } + private record HandlerEntry(int priority, Consumer handler) {} } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/PluginManager.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/PluginManager.java similarity index 94% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/PluginManager.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/PluginManager.java index 21ba8eeee..5fd1160af 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/PluginManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/PluginManager.java @@ -13,8 +13,6 @@ import de.maxhenkel.voicechat.voice.common.*; import de.maxhenkel.voicechat.voice.server.Group; import de.maxhenkel.voicechat.voice.server.Server; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; import javax.annotation.Nullable; import java.util.*; @@ -53,8 +51,8 @@ private void gatherEvents() { Voicechat.LOGGER.info("Registering events for '{}'", plugin.getPluginId()); try { plugin.registerEvents(registration); - } catch (Throwable e) { - Voicechat.LOGGER.warn("Failed to register events for plugin '{}'", plugin.getPluginId(), e); + } catch (Throwable t) { + Voicechat.LOGGER.error("Failed to register events for '{}'", plugin.getPluginId(), t); } } events = eventBuilder.build(); @@ -122,7 +120,11 @@ public void onListenerAudio(UUID playerUuid, SoundPacket packet) { for (PlayerAudioListener l : listeners) { if (l instanceof PlayerAudioListenerImpl) { - ((PlayerAudioListenerImpl) l).getListener().accept(soundPacket); + try { + ((PlayerAudioListenerImpl) l).getListener().accept(soundPacket); + } catch (Throwable t) { + Voicechat.LOGGER.error("Failed to process audio listener", t); + } } } } @@ -139,8 +141,8 @@ public boolean dispatchEvent(Class eventClass, T if (event.isCancelled()) { break; } - } catch (Exception e) { - Voicechat.LOGGER.error("Failed to dispatch event '{}'", event.getClass().getSimpleName(), e); + } catch (Throwable t) { + Voicechat.LOGGER.error("Failed to dispatch event '{}'", eventClass.getSimpleName(), t); } } return event.isCancelled(); @@ -216,7 +218,7 @@ public boolean onLeaveGroup(ServerPlayer player) { return false; } @Nullable GroupImpl group = null; - PlayerState state = server.getPlayerStateManager().getState(player.getUUID()); + PlayerState state = server.getPlayerStateManager().getState(player.getUuid()); if (state != null) { UUID groupUUID = state.getGroup(); if (groupUUID != null) { @@ -236,13 +238,13 @@ public boolean onRemoveGroup(Group group) { public boolean onMicPacket(ServerPlayer sender, PlayerState senderState, MicPacket packet) { return dispatchEvent(MicrophonePacketEvent.class, new MicrophonePacketEventImpl( - new MicrophonePacketImpl(packet, sender.getUUID()), + new MicrophonePacketImpl(packet, sender.getUuid()), new VoicechatConnectionImpl(sender, senderState) )); } public float getDistance(ServerPlayer sender, PlayerState senderState, MicPacket packet, float originalDistance) { - VoiceDistanceEventImpl event = new VoiceDistanceEventImpl(new MicrophonePacketImpl(packet, sender.getUUID()), new VoicechatConnectionImpl(sender, senderState), originalDistance); + VoiceDistanceEventImpl event = new VoiceDistanceEventImpl(new MicrophonePacketImpl(packet, sender.getUuid()), new VoicechatConnectionImpl(sender, senderState), originalDistance); dispatchEvent(VoiceDistanceEvent.class, event); return event.getDistance(); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/GroupImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/GroupImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/GroupImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/GroupImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/RawUdpPacketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/RawUdpPacketImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/RawUdpPacketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/RawUdpPacketImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatApiImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatApiImpl.java similarity index 64% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatApiImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatApiImpl.java index 7aa83f089..69d50b227 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatApiImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatApiImpl.java @@ -1,6 +1,7 @@ package de.maxhenkel.voicechat.plugins.impl; -import de.maxhenkel.voicechat.api.*; +import de.maxhenkel.voicechat.api.VoicechatApi; +import de.maxhenkel.voicechat.api.VolumeCategory; import de.maxhenkel.voicechat.api.audio.AudioConverter; import de.maxhenkel.voicechat.api.mp3.Mp3Decoder; import de.maxhenkel.voicechat.api.mp3.Mp3Encoder; @@ -8,9 +9,9 @@ import de.maxhenkel.voicechat.api.opus.OpusEncoder; import de.maxhenkel.voicechat.api.opus.OpusEncoderMode; import de.maxhenkel.voicechat.natives.LameManager; +import de.maxhenkel.voicechat.natives.OpusManager; import de.maxhenkel.voicechat.plugins.impl.audio.AudioConverterImpl; import de.maxhenkel.voicechat.plugins.impl.mp3.Mp3DecoderImpl; -import de.maxhenkel.voicechat.natives.OpusManager; import de.maxhenkel.voicechat.voice.common.Utils; import javax.annotation.Nullable; @@ -53,38 +54,6 @@ public AudioConverter getAudioConverter() { return AUDIO_CONVERTER; } - @Override - public Entity fromEntity(Object entity) { - if (entity instanceof net.minecraft.world.entity.Entity e) { - return new EntityImpl(e); - } else { - throw new IllegalArgumentException("entity is not an instance of Entity"); - } - } - - @Override - public ServerLevel fromServerLevel(Object serverLevel) { - if (serverLevel instanceof net.minecraft.server.level.ServerLevel l) { - return new ServerLevelImpl(l); - } else { - throw new IllegalArgumentException("serverLevel is not an instance of ServerLevel"); - } - } - - @Override - public ServerPlayer fromServerPlayer(Object serverPlayer) { - if (serverPlayer instanceof net.minecraft.server.level.ServerPlayer p) { - return new ServerPlayerImpl(p); - } else { - throw new IllegalArgumentException("serverPlayer is not an instance of ServerPlayer"); - } - } - - @Override - public Position createPosition(double x, double y, double z) { - return new PositionImpl(x, y, z); - } - @Override public VolumeCategory.Builder volumeCategoryBuilder() { return new VolumeCategoryImpl.BuilderImpl(); diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatConnectionImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatConnectionImpl.java similarity index 89% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatConnectionImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatConnectionImpl.java index f2a12ce1a..c5b216bc1 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatConnectionImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatConnectionImpl.java @@ -12,21 +12,19 @@ public class VoicechatConnectionImpl implements VoicechatConnection { - private final ServerPlayer player; - private final net.minecraft.server.level.ServerPlayer serverPlayer; + private final ServerPlayer serverPlayer; private final PlayerState state; @Nullable private final Group group; - public VoicechatConnectionImpl(net.minecraft.server.level.ServerPlayer player, PlayerState state) { + public VoicechatConnectionImpl(ServerPlayer player, PlayerState state) { this.serverPlayer = player; - this.player = new ServerPlayerImpl(player); this.state = state; this.group = GroupImpl.create(state); } @Nullable - public static VoicechatConnectionImpl fromPlayer(@Nullable net.minecraft.server.level.ServerPlayer player) { + public static VoicechatConnectionImpl fromPlayer(@Nullable ServerPlayer player) { if (player == null) { return null; } @@ -34,7 +32,7 @@ public static VoicechatConnectionImpl fromPlayer(@Nullable net.minecraft.server. if (server == null) { return null; } - PlayerState state = server.getPlayerStateManager().getState(player.getUUID()); + PlayerState state = server.getPlayerStateManager().getState(player.getUuid()); if (state == null) { return null; } @@ -131,7 +129,7 @@ public boolean isInstalled() { @Override public ServerPlayer getPlayer() { - return player; + return serverPlayer; } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatServerApiImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatServerApiImpl.java similarity index 87% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatServerApiImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatServerApiImpl.java index c638c3adf..0a6c3831c 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatServerApiImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatServerApiImpl.java @@ -33,7 +33,6 @@ import java.util.UUID; import java.util.function.Predicate; import java.util.function.Supplier; -import java.util.stream.Collectors; public class VoicechatServerApiImpl extends VoicechatApiImpl implements VoicechatServerApi { @@ -86,11 +85,7 @@ public LocationalAudioChannel createLocationalAudioChannel(UUID channelId, Serve if (server == null) { return null; } - if (initialPosition instanceof PositionImpl p) { - return new LocationalAudioChannelImpl(channelId, server, level, p); - } else { - throw new IllegalArgumentException("initialPosition is not an instance of PositionImpl"); - } + return new LocationalAudioChannelImpl(channelId, server, level, initialPosition); } @Nullable @@ -168,22 +163,19 @@ public boolean unregisterAudioListener(UUID listenerId) { } public static void sendPacket(VoicechatConnection receiver, SoundPacket soundPacket) { - if (!(receiver.getPlayer() instanceof ServerPlayerImpl serverPlayerImpl)) { - throw new IllegalArgumentException("ServerPlayer is not an instance of ServerPlayerImpl"); - } - sendPacket(serverPlayerImpl.getRealServerPlayer(), soundPacket); + sendPacket(receiver.getPlayer(), soundPacket); } - public static void sendPacket(net.minecraft.server.level.ServerPlayer receiver, SoundPacket soundPacket) { + public static void sendPacket(ServerPlayer receiver, SoundPacket soundPacket) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return; } - PlayerState state = server.getPlayerStateManager().getState(receiver.getUUID()); + PlayerState state = server.getPlayerStateManager().getState(receiver.getUuid()); if (state == null) { return; } - @Nullable ClientConnection c = server.getConnections().get(receiver.getUUID()); + @Nullable ClientConnection c = server.getConnections().get(receiver.getUuid()); server.sendSoundPacket(null, null, receiver, state, c, soundPacket, SoundPacketEvent.SOURCE_PLUGIN); } @@ -194,7 +186,7 @@ public VoicechatConnection getConnectionOf(UUID playerUuid) { if (server == null) { return null; } - net.minecraft.server.level.ServerPlayer player = server.getServer().getPlayerList().getPlayer(playerUuid); + ServerPlayer player = server.getServer().getPlayer(playerUuid); if (player == null) { return null; } @@ -252,13 +244,7 @@ public UUID getSecret(UUID userId) { @Override public Collection getPlayersInRange(ServerLevel level, Position pos, double range, @Nullable Predicate filter) { - if (!(pos instanceof PositionImpl p)) { - throw new IllegalArgumentException("Position is not an instance of PositionImpl"); - } - if (!(level instanceof ServerLevelImpl serverLevel)) { - throw new IllegalArgumentException("ServerLevel is not an instance of ServerLevelImpl"); - } - return ServerWorldUtils.getPlayersInRange(serverLevel.getRawServerLevel(), p.getPosition(), range, filter == null ? null : player -> filter.test(new ServerPlayerImpl(player))).stream().map(ServerPlayerImpl::new).collect(Collectors.toList()); + return ServerWorldUtils.getPlayersInRange(level, pos, range, filter); } @Override diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketBase.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketBase.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketBase.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketBase.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VoicechatSocketImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VolumeCategoryImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VolumeCategoryImpl.java similarity index 79% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VolumeCategoryImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VolumeCategoryImpl.java index a9c6575ff..203855a9b 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/VolumeCategoryImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/VolumeCategoryImpl.java @@ -1,9 +1,8 @@ package de.maxhenkel.voicechat.plugins.impl; import de.maxhenkel.voicechat.api.VolumeCategory; -import net.minecraft.locale.Language; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; +import de.maxhenkel.voicechat.voice.common.BufferUtils; +import io.netty.buffer.ByteBuf; import javax.annotation.Nullable; import java.util.regex.Pattern; @@ -51,34 +50,12 @@ public String getNameTranslationKey() { return nameTranslationKey; } - public Component getDisplayName() { - if (nameTranslationKey != null) { - return Component.translatableWithFallback(nameTranslationKey, name); - } - return Component.literal(name); - } - - public String getSearchName() { - if (nameTranslationKey == null) { - return name; - } - Language lang = Language.getInstance(); - return lang.getOrDefault(nameTranslationKey, name); - } - @Nullable @Override public String getDescription() { return description; } - public Component getDisplayDescription() { - if (descriptionTranslationKey != null) { - return Component.translatableWithFallback(descriptionTranslationKey, description); - } - return description != null ? Component.literal(description) : Component.empty(); - } - @Override @Nullable public String getDescriptionTranslationKey() { @@ -91,9 +68,9 @@ public int[][] getIcon() { return icon; } - public static VolumeCategoryImpl fromBytes(FriendlyByteBuf buf) { - String id = buf.readUtf(16); - String name = buf.readUtf(16); + public static VolumeCategoryImpl fromBytes(ByteBuf buf) { + String id = BufferUtils.readUtf(buf, 16); + String name = BufferUtils.readUtf(buf, 16); String nameTranslationKey = readOptionalString(buf); String description = readOptionalString(buf); String descriptionTranslationKey = readOptionalString(buf); @@ -110,16 +87,16 @@ public static VolumeCategoryImpl fromBytes(FriendlyByteBuf buf) { } @Nullable - private static String readOptionalString(FriendlyByteBuf buf) { + private static String readOptionalString(ByteBuf buf) { if (buf.readBoolean()) { - return buf.readUtf(32767); + return BufferUtils.readUtf(buf); } return null; } - public void toBytes(FriendlyByteBuf buf) { - buf.writeUtf(id, 16); - buf.writeUtf(name, 16); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUtf(buf, id, 16); + BufferUtils.writeUtf(buf, name, 16); writeOptionalString(buf, nameTranslationKey); writeOptionalString(buf, description); writeOptionalString(buf, descriptionTranslationKey); @@ -139,10 +116,10 @@ public void toBytes(FriendlyByteBuf buf) { } } - private static void writeOptionalString(FriendlyByteBuf buf, @Nullable String string) { + private static void writeOptionalString(ByteBuf buf, @Nullable String string) { buf.writeBoolean(string != null); if (string != null) { - buf.writeUtf(string, 32767); + BufferUtils.writeUtf(buf, string, 32767); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audio/AudioConverterImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audio/AudioConverterImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audio/AudioConverterImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audio/AudioConverterImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioChannelImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioChannelImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioChannelImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioChannelImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioPlayerImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioPlayerImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioPlayerImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioPlayerImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioSupplier.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioSupplier.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioSupplier.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/AudioSupplier.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/EntityAudioChannelImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/EntityAudioChannelImpl.java similarity index 77% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/EntityAudioChannelImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/EntityAudioChannelImpl.java index 582c27231..19c368e27 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/EntityAudioChannelImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/EntityAudioChannelImpl.java @@ -4,13 +4,10 @@ import de.maxhenkel.voicechat.api.audiochannel.EntityAudioChannel; import de.maxhenkel.voicechat.api.events.SoundPacketEvent; import de.maxhenkel.voicechat.api.packets.MicrophonePacket; -import de.maxhenkel.voicechat.plugins.impl.EntityImpl; -import de.maxhenkel.voicechat.plugins.impl.ServerPlayerImpl; import de.maxhenkel.voicechat.voice.common.PlayerSoundPacket; import de.maxhenkel.voicechat.voice.common.Utils; import de.maxhenkel.voicechat.voice.server.Server; import de.maxhenkel.voicechat.voice.server.ServerWorldUtils; -import net.minecraft.server.level.ServerLevel; import java.util.UUID; @@ -73,10 +70,7 @@ public void flush() { } private void broadcast(PlayerSoundPacket packet) { - if (!(entity instanceof EntityImpl entityimpl)) { - throw new IllegalArgumentException("entity is not an instance of EntityImpl"); - } - server.broadcast(ServerWorldUtils.getPlayersInRange((ServerLevel) entityimpl.getRealEntity().level(), entityimpl.getRealEntity().getEyePosition(), server.getBroadcastRange(distance), filter == null ? player -> true : player -> filter.test(new ServerPlayerImpl(player))), packet, null, null, null, SoundPacketEvent.SOURCE_PLUGIN); + server.broadcast(ServerWorldUtils.getPlayersInRange(entity.getLevel(), entity.getEyePosition(), server.getBroadcastRange(distance), filter == null ? player -> true : player -> filter.test(player)), packet, null, null, null, SoundPacketEvent.SOURCE_PLUGIN); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/LocationalAudioChannelImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/LocationalAudioChannelImpl.java similarity index 60% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/LocationalAudioChannelImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/LocationalAudioChannelImpl.java index c90e176b8..f599d672f 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/LocationalAudioChannelImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/LocationalAudioChannelImpl.java @@ -5,9 +5,6 @@ import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel; import de.maxhenkel.voicechat.api.events.SoundPacketEvent; import de.maxhenkel.voicechat.api.packets.MicrophonePacket; -import de.maxhenkel.voicechat.plugins.impl.PositionImpl; -import de.maxhenkel.voicechat.plugins.impl.ServerLevelImpl; -import de.maxhenkel.voicechat.plugins.impl.ServerPlayerImpl; import de.maxhenkel.voicechat.voice.common.LocationSoundPacket; import de.maxhenkel.voicechat.voice.common.Utils; import de.maxhenkel.voicechat.voice.server.Server; @@ -18,10 +15,10 @@ public class LocationalAudioChannelImpl extends AudioChannelImpl implements LocationalAudioChannel { protected ServerLevel level; - protected PositionImpl position; + protected Position position; protected float distance; - public LocationalAudioChannelImpl(UUID channelId, Server server, ServerLevel level, PositionImpl position) { + public LocationalAudioChannelImpl(UUID channelId, Server server, ServerLevel level, Position position) { super(channelId, server); this.level = level; this.position = position; @@ -30,11 +27,7 @@ public LocationalAudioChannelImpl(UUID channelId, Server server, ServerLevel lev @Override public void updateLocation(Position position) { - if (position instanceof PositionImpl p) { - this.position = p; - } else { - throw new IllegalArgumentException("position is not an instance of PositionImpl"); - } + this.position = position; } @Override @@ -54,7 +47,7 @@ public void setDistance(float distance) { @Override public void send(byte[] opusData) { - broadcast(new LocationSoundPacket(channelId, channelId, position.getPosition(), opusData, sequenceNumber.getAndIncrement(), distance, category)); + broadcast(new LocationSoundPacket(channelId, channelId, position, opusData, sequenceNumber.getAndIncrement(), distance, category)); } @Override @@ -64,14 +57,11 @@ public void send(MicrophonePacket packet) { @Override public void flush() { - broadcast(new LocationSoundPacket(channelId, channelId, position.getPosition(), new byte[0], sequenceNumber.getAndIncrement(), distance, category)); + broadcast(new LocationSoundPacket(channelId, channelId, position, new byte[0], sequenceNumber.getAndIncrement(), distance, category)); } private void broadcast(LocationSoundPacket packet) { - if (!(level instanceof ServerLevelImpl serverLevel)) { - throw new IllegalArgumentException("level is not an instance of ServerLevelImpl"); - } - server.broadcast(ServerWorldUtils.getPlayersInRange(serverLevel.getRawServerLevel(), position.getPosition(), server.getBroadcastRange(distance), filter == null ? player -> true : player -> filter.test(new ServerPlayerImpl(player))), packet, null, null, null, SoundPacketEvent.SOURCE_PLUGIN); + server.broadcast(ServerWorldUtils.getPlayersInRange(level, position, server.getBroadcastRange(distance), filter == null ? player -> true : player -> filter.test(player)), packet, null, null, null, SoundPacketEvent.SOURCE_PLUGIN); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/StaticAudioChannelImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/StaticAudioChannelImpl.java similarity index 88% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/StaticAudioChannelImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/StaticAudioChannelImpl.java index 19e3fea95..0225725ec 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/StaticAudioChannelImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiochannel/StaticAudioChannelImpl.java @@ -1,19 +1,20 @@ package de.maxhenkel.voicechat.plugins.impl.audiochannel; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import de.maxhenkel.voicechat.api.VoicechatConnection; import de.maxhenkel.voicechat.api.audiochannel.StaticAudioChannel; import de.maxhenkel.voicechat.api.packets.MicrophonePacket; -import de.maxhenkel.voicechat.plugins.impl.ServerPlayerImpl; import de.maxhenkel.voicechat.plugins.impl.VoicechatServerApiImpl; import de.maxhenkel.voicechat.voice.common.GroupSoundPacket; import de.maxhenkel.voicechat.voice.server.ClientConnection; import de.maxhenkel.voicechat.voice.server.Group; import de.maxhenkel.voicechat.voice.server.Server; import de.maxhenkel.voicechat.voice.server.ServerGroupManager; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.players.PlayerList; -import java.util.*; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; public class StaticAudioChannelImpl extends AudioChannelImpl implements StaticAudioChannel { @@ -43,14 +44,14 @@ public void flush() { private void broadcast(GroupSoundPacket packet) { synchronized (targets) { - PlayerList playerList = server.getServer().getPlayerList(); + MinecraftServer minecraftServer = server.getServer(); ServerGroupManager groupManager = server.getGroupManager(); for (UUID target : targets) { ClientConnection connection = server.getConnection(target); if (connection == null) { continue; } - ServerPlayer player = playerList.getPlayer(target); + ServerPlayer player = minecraftServer.getPlayer(target); if (player == null) { continue; } @@ -61,7 +62,7 @@ private void broadcast(GroupSoundPacket packet) { } } if (filter != null) { - if (!filter.test(new ServerPlayerImpl(player))) { + if (!filter.test(player)) { continue; } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiolistener/PlayerAudioListenerImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiolistener/PlayerAudioListenerImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiolistener/PlayerAudioListenerImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiolistener/PlayerAudioListenerImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiosender/AudioSenderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiosender/AudioSenderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiosender/AudioSenderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/audiosender/AudioSenderImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/config/ConfigAccessorImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/config/ConfigAccessorImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/config/ConfigAccessorImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/config/ConfigAccessorImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/CreateGroupEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/CreateGroupEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/CreateGroupEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/CreateGroupEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EntitySoundPacketEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EntitySoundPacketEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EntitySoundPacketEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EntitySoundPacketEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/EventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/GroupEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/GroupEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/GroupEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/GroupEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/JoinGroupEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/JoinGroupEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/JoinGroupEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/JoinGroupEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LeaveGroupEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LeaveGroupEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LeaveGroupEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LeaveGroupEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LocationalSoundPacketEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LocationalSoundPacketEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LocationalSoundPacketEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/LocationalSoundPacketEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/MicrophonePacketEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/MicrophonePacketEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/MicrophonePacketEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/MicrophonePacketEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PacketEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PacketEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PacketEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PacketEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerConnectedEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerConnectedEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerConnectedEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerConnectedEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerDisconnectedEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerDisconnectedEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerDisconnectedEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerDisconnectedEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerStateChangedEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerStateChangedEventImpl.java similarity index 90% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerStateChangedEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerStateChangedEventImpl.java index 4b1b0e19f..fc99a2fed 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerStateChangedEventImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/PlayerStateChangedEventImpl.java @@ -6,7 +6,7 @@ import de.maxhenkel.voicechat.plugins.impl.VoicechatConnectionImpl; import de.maxhenkel.voicechat.voice.common.PlayerState; import de.maxhenkel.voicechat.voice.server.Server; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.ServerPlayer; import javax.annotation.Nullable; import java.util.UUID; @@ -44,7 +44,7 @@ public VoicechatConnection getConnection() { if (server == null) { return null; } - ServerPlayer player = server.getServer().getPlayerList().getPlayer(state.getUuid()); + ServerPlayer player = server.getServer().getPlayer(state.getUuid()); if (player == null) { return null; } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RegisterVolumeCategoryEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RegisterVolumeCategoryEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RegisterVolumeCategoryEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RegisterVolumeCategoryEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RemoveGroupEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RemoveGroupEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RemoveGroupEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/RemoveGroupEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/ServerEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/ServerEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/ServerEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/ServerEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/SoundPacketEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/SoundPacketEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/SoundPacketEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/SoundPacketEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/StaticSoundPacketEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/StaticSoundPacketEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/StaticSoundPacketEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/StaticSoundPacketEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/UnregisterVolumeCategoryEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/UnregisterVolumeCategoryEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/UnregisterVolumeCategoryEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/UnregisterVolumeCategoryEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceDistanceEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceDistanceEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceDistanceEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceDistanceEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceHostEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceHostEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceHostEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoiceHostEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartedEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartedEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartedEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartedEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartingEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartingEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartingEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStartingEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStoppedEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStoppedEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStoppedEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VoicechatServerStoppedEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VolumeCategoryEventImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VolumeCategoryEventImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VolumeCategoryEventImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/events/VolumeCategoryEventImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3DecoderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3DecoderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3DecoderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3DecoderImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3EncoderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3EncoderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3EncoderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/mp3/Mp3EncoderImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusDecoderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusDecoderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusDecoderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusDecoderImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java index 6dc07700f..86c371734 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/JavaOpusEncoderImpl.java @@ -1,8 +1,8 @@ package de.maxhenkel.voicechat.plugins.impl.opus; +import de.maxhenkel.opus4j.OpusEncoder.Application; import org.concentus.OpusApplication; import org.concentus.OpusEncoder; -import de.maxhenkel.opus4j.OpusEncoder.Application; public class JavaOpusEncoderImpl implements de.maxhenkel.voicechat.api.opus.OpusEncoder { diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusDecoderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusDecoderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusDecoderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusDecoderImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusEncoderImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusEncoderImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusEncoderImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/opus/NativeOpusEncoderImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/EntitySoundPacketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/EntitySoundPacketImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/EntitySoundPacketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/EntitySoundPacketImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/LocationalSoundPacketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/LocationalSoundPacketImpl.java similarity index 86% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/LocationalSoundPacketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/LocationalSoundPacketImpl.java index 00ea5644d..25f813122 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/LocationalSoundPacketImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/LocationalSoundPacketImpl.java @@ -2,7 +2,6 @@ import de.maxhenkel.voicechat.api.Position; import de.maxhenkel.voicechat.api.packets.LocationalSoundPacket; -import de.maxhenkel.voicechat.plugins.impl.PositionImpl; import de.maxhenkel.voicechat.voice.common.LocationSoundPacket; import de.maxhenkel.voicechat.voice.common.Utils; @@ -12,12 +11,12 @@ public class LocationalSoundPacketImpl extends SoundPacketImpl implements LocationalSoundPacket { private final LocationSoundPacket packet; - private final PositionImpl position; + private final Position position; public LocationalSoundPacketImpl(LocationSoundPacket packet) { super(packet); this.packet = packet; - this.position = new PositionImpl(packet.getLocation()); + this.position = packet.getLocation(); } public Position getPosition() { @@ -36,7 +35,7 @@ public LocationSoundPacket getPacket() { public static class BuilderImpl extends SoundPacketImpl.BuilderImpl implements LocationalSoundPacket.Builder { - protected PositionImpl position; + protected Position position; protected float distance; public BuilderImpl(SoundPacketImpl soundPacket) { @@ -58,7 +57,7 @@ public BuilderImpl(UUID channelId, UUID sender, byte[] opusEncodedData, long seq @Override public BuilderImpl position(Position position) { - this.position = (PositionImpl) position; + this.position = position; return this; } @@ -73,7 +72,7 @@ public LocationalSoundPacket build() { if (position == null) { throw new IllegalStateException("position missing"); } - return new LocationalSoundPacketImpl(new LocationSoundPacket(channelId, sender, position.getPosition(), opusEncodedData, sequenceNumber, distance, category)); + return new LocationalSoundPacketImpl(new LocationSoundPacket(channelId, sender, position, opusEncodedData, sequenceNumber, distance, category)); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/MicrophonePacketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/MicrophonePacketImpl.java similarity index 84% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/MicrophonePacketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/MicrophonePacketImpl.java index 324244836..a97ef5cd0 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/MicrophonePacketImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/MicrophonePacketImpl.java @@ -5,7 +5,6 @@ import de.maxhenkel.voicechat.api.packets.LocationalSoundPacket; import de.maxhenkel.voicechat.api.packets.MicrophonePacket; import de.maxhenkel.voicechat.api.packets.StaticSoundPacket; -import de.maxhenkel.voicechat.plugins.impl.PositionImpl; import de.maxhenkel.voicechat.voice.common.*; import java.util.Objects; @@ -60,11 +59,7 @@ public EntitySoundPacket toEntitySoundPacket(UUID entityUuid, boolean whispering @Override @Deprecated public LocationalSoundPacket toLocationalSoundPacket(Position position) { - if (position instanceof PositionImpl p) { - return new LocationalSoundPacketImpl(new LocationSoundPacket(sender, sender, p.getPosition(), packet.getData(), packet.getSequenceNumber(), Utils.getDefaultDistanceServer(), null)); - } else { - throw new IllegalArgumentException("position is not an instance of PositionImpl"); - } + return new LocationalSoundPacketImpl(new LocationSoundPacket(sender, sender, position, packet.getData(), packet.getSequenceNumber(), Utils.getDefaultDistanceServer(), null)); } @Override diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/SoundPacketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/SoundPacketImpl.java similarity index 91% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/SoundPacketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/SoundPacketImpl.java index dc873f104..7a03ed144 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/SoundPacketImpl.java +++ b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/SoundPacketImpl.java @@ -5,7 +5,6 @@ import de.maxhenkel.voicechat.api.packets.LocationalSoundPacket; import de.maxhenkel.voicechat.api.packets.SoundPacket; import de.maxhenkel.voicechat.api.packets.StaticSoundPacket; -import de.maxhenkel.voicechat.plugins.impl.PositionImpl; import de.maxhenkel.voicechat.voice.common.GroupSoundPacket; import de.maxhenkel.voicechat.voice.common.LocationSoundPacket; import de.maxhenkel.voicechat.voice.common.PlayerSoundPacket; @@ -74,11 +73,7 @@ public EntitySoundPacket toEntitySoundPacket(UUID entityUuid, boolean whispering @Override public LocationalSoundPacket toLocationalSoundPacket(Position position) { - if (position instanceof PositionImpl p) { - return new LocationalSoundPacketImpl(new LocationSoundPacket(packet.getChannelId(), packet.getSender(), p.getPosition(), packet.getData(), packet.getSequenceNumber(), getDistance(), null)); - } else { - throw new IllegalArgumentException("position is not an instance of PositionImpl"); - } + return new LocationalSoundPacketImpl(new LocationSoundPacket(packet.getChannelId(), packet.getSender(), position, packet.getData(), packet.getSequenceNumber(), getDistance(), null)); } private float getDistance() { diff --git a/common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/StaticSoundPacketImpl.java b/core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/StaticSoundPacketImpl.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/StaticSoundPacketImpl.java rename to core/src/main/java/de/maxhenkel/voicechat/plugins/impl/packets/StaticSoundPacketImpl.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/service/Service.java b/core/src/main/java/de/maxhenkel/voicechat/service/Service.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/service/Service.java rename to core/src/main/java/de/maxhenkel/voicechat/service/Service.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/AudioUtils.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/AudioUtils.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/AudioUtils.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/AudioUtils.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticateAckPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticateAckPacket.java similarity index 61% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticateAckPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticateAckPacket.java index 7406531b6..f9c6f82cc 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticateAckPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticateAckPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; public class AuthenticateAckPacket implements Packet { @@ -9,12 +9,12 @@ public AuthenticateAckPacket() { } @Override - public AuthenticateAckPacket fromBytes(FriendlyByteBuf buf) { + public AuthenticateAckPacket fromBytes(ByteBuf buf) { return new AuthenticateAckPacket(); } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticatePacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticatePacket.java similarity index 75% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticatePacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticatePacket.java index ad3dddb49..6f6894c23 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticatePacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/AuthenticatePacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import java.util.UUID; @@ -27,16 +27,16 @@ public Secret getSecret() { } @Override - public AuthenticatePacket fromBytes(FriendlyByteBuf buf) { + public AuthenticatePacket fromBytes(ByteBuf buf) { AuthenticatePacket packet = new AuthenticatePacket(); - packet.playerUUID = buf.readUUID(); + packet.playerUUID = BufferUtils.readUUID(buf); packet.secret = Secret.fromBytes(buf); return packet; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(playerUUID); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, playerUUID); secret.toBytes(buf); } } diff --git a/core/src/main/java/de/maxhenkel/voicechat/voice/common/BufferUtils.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/BufferUtils.java new file mode 100644 index 000000000..392768b31 --- /dev/null +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/BufferUtils.java @@ -0,0 +1,111 @@ +package de.maxhenkel.voicechat.voice.common; + +import io.netty.buffer.ByteBuf; + +import java.nio.charset.StandardCharsets; +import java.util.UUID; + +public class BufferUtils { + + public static UUID readUUID(ByteBuf buf) { + return new UUID(buf.readLong(), buf.readLong()); + } + + public static void writeUUID(ByteBuf buf, UUID id) { + buf.writeLong(id.getMostSignificantBits()); + buf.writeLong(id.getLeastSignificantBits()); + } + + public static String readUtf(ByteBuf buf) { + return readUtf(buf, 32767); + } + + public static String readUtf(ByteBuf buf, int i) { + int j = getMaxEncodedUtfLength(i); + int k = readVarInt(buf); + if (k > j) { + throw new RuntimeException("The received encoded string buffer length is longer than maximum allowed (" + k + " > " + j + ")"); + } else if (k < 0) { + throw new RuntimeException("The received encoded string buffer length is less than zero! Weird string!"); + } else { + String string = buf.toString(buf.readerIndex(), k, StandardCharsets.UTF_8); + buf.readerIndex(buf.readerIndex() + k); + if (string.length() > i) { + int var10002 = string.length(); + throw new RuntimeException("The received string length is longer than maximum allowed (" + var10002 + " > " + i + ")"); + } else { + return string; + } + } + } + + public static void writeUtf(ByteBuf buf, String string) { + writeUtf(buf, string, 32767); + } + + public static void writeUtf(ByteBuf buf, String string, int i) { + if (string.length() > i) { + int var10002 = string.length(); + throw new RuntimeException("String too big (was " + var10002 + " characters, max " + i + ")"); + } else { + byte[] bs = string.getBytes(StandardCharsets.UTF_8); + int j = getMaxEncodedUtfLength(i); + if (bs.length > j) { + throw new RuntimeException("String too big (was " + bs.length + " bytes encoded, max " + j + ")"); + } else { + writeVarInt(buf, bs.length); + buf.writeBytes(bs); + } + } + } + + public static byte[] readByteArray(ByteBuf buf) { + return readByteArray(buf, buf.readableBytes()); + } + + public static void writeByteArray(ByteBuf buf, byte[] bytes) { + writeVarInt(buf, bytes.length); + buf.writeBytes(bytes); + } + + private static int getMaxEncodedUtfLength(int i) { + return i * 3; + } + + public static int readVarInt(ByteBuf buf) { + int i = 0; + int j = 0; + + byte b; + do { + b = buf.readByte(); + i |= (b & 127) << j++ * 7; + if (j > 5) { + throw new RuntimeException("VarInt too big"); + } + } while((b & 128) == 128); + + return i; + } + + + public static byte[] readByteArray(ByteBuf buf, int i) { + int j = readVarInt(buf); + if (j > i) { + throw new RuntimeException("ByteArray with size " + j + " is bigger than allowed " + i); + } else { + byte[] bs = new byte[j]; + buf.readBytes(bs); + return bs; + } + } + + public static void writeVarInt(ByteBuf buf, int i) { + while((i & -128) != 0) { + buf.writeByte(i & 127 | 128); + i >>>= 7; + } + + buf.writeByte(i); + } +} diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/ClientGroup.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ClientGroup.java similarity index 80% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/ClientGroup.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/ClientGroup.java index 5d9e8b329..ad83a5309 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/ClientGroup.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ClientGroup.java @@ -2,7 +2,7 @@ import de.maxhenkel.voicechat.api.Group; import de.maxhenkel.voicechat.plugins.impl.GroupImpl; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import java.util.Objects; import java.util.UUID; @@ -49,13 +49,13 @@ public Group.Type getType() { return type; } - public static ClientGroup fromBytes(FriendlyByteBuf buf) { - return new ClientGroup(buf.readUUID(), buf.readUtf(512), buf.readBoolean(), buf.readBoolean(), buf.readBoolean(), GroupImpl.TypeImpl.fromInt(buf.readShort())); + public static ClientGroup fromBytes(ByteBuf buf) { + return new ClientGroup(BufferUtils.readUUID(buf), BufferUtils.readUtf(buf, 512), buf.readBoolean(), buf.readBoolean(), buf.readBoolean(), GroupImpl.TypeImpl.fromInt(buf.readShort())); } - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(id); - buf.writeUtf(name, 512); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, id); + BufferUtils.writeUtf(buf, name, 512); buf.writeBoolean(hasPassword); buf.writeBoolean(persistent); buf.writeBoolean(hidden); diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckAckPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckAckPacket.java similarity index 62% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckAckPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckAckPacket.java index 333ed2148..ecb4be208 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckAckPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckAckPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; public class ConnectionCheckAckPacket implements Packet { @@ -9,12 +9,12 @@ public ConnectionCheckAckPacket() { } @Override - public ConnectionCheckAckPacket fromBytes(FriendlyByteBuf buf) { + public ConnectionCheckAckPacket fromBytes(ByteBuf buf) { return new ConnectionCheckAckPacket(); } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckPacket.java similarity index 61% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckPacket.java index bcb7139fe..580c2216b 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ConnectionCheckPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; public class ConnectionCheckPacket implements Packet { @@ -9,12 +9,12 @@ public ConnectionCheckPacket() { } @Override - public ConnectionCheckPacket fromBytes(FriendlyByteBuf buf) { + public ConnectionCheckPacket fromBytes(ByteBuf buf) { return new ConnectionCheckPacket(); } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/GroupSoundPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/GroupSoundPacket.java similarity index 66% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/GroupSoundPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/GroupSoundPacket.java index 36ec9536a..433dd35ff 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/GroupSoundPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/GroupSoundPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import javax.annotation.Nullable; import java.util.UUID; @@ -20,25 +20,25 @@ public GroupSoundPacket() { } @Override - public GroupSoundPacket fromBytes(FriendlyByteBuf buf) { + public GroupSoundPacket fromBytes(ByteBuf buf) { GroupSoundPacket soundPacket = new GroupSoundPacket(); - soundPacket.channelId = buf.readUUID(); - soundPacket.sender = buf.readUUID(); - soundPacket.data = buf.readByteArray(); + soundPacket.channelId = BufferUtils.readUUID(buf); + soundPacket.sender = BufferUtils.readUUID(buf); + soundPacket.data = BufferUtils.readByteArray(buf); soundPacket.sequenceNumber = buf.readLong(); byte data = buf.readByte(); if (hasFlag(data, HAS_CATEGORY_MASK)) { - soundPacket.category = buf.readUtf(16); + soundPacket.category = BufferUtils.readUtf(buf, 16); } return soundPacket; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(channelId); - buf.writeUUID(sender); - buf.writeByteArray(data); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, channelId); + BufferUtils.writeUUID(buf, sender); + BufferUtils.writeByteArray(buf, data); buf.writeLong(sequenceNumber); byte data = 0b0; @@ -47,7 +47,7 @@ public void toBytes(FriendlyByteBuf buf) { } buf.writeByte(data); if (category != null) { - buf.writeUtf(category, 16); + BufferUtils.writeUtf(buf, category, 16); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/KeepAlivePacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/KeepAlivePacket.java similarity index 60% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/KeepAlivePacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/KeepAlivePacket.java index 1c1a4b385..c9487ab1e 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/KeepAlivePacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/KeepAlivePacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; public class KeepAlivePacket implements Packet { @@ -9,12 +9,12 @@ public KeepAlivePacket() { } @Override - public KeepAlivePacket fromBytes(FriendlyByteBuf buf) { + public KeepAlivePacket fromBytes(ByteBuf buf) { return new KeepAlivePacket(); } @Override - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/LocationSoundPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/LocationSoundPacket.java similarity index 50% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/LocationSoundPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/LocationSoundPacket.java index a8e816ff7..e62029b7e 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/LocationSoundPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/LocationSoundPacket.java @@ -1,23 +1,24 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.phys.Vec3; +import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import io.netty.buffer.ByteBuf; +import de.maxhenkel.voicechat.api.Position; import javax.annotation.Nullable; import java.util.UUID; public class LocationSoundPacket extends SoundPacket { - protected Vec3 location; + protected Position location; protected float distance; - public LocationSoundPacket(UUID channelId, UUID sender, Vec3 location, byte[] data, long sequenceNumber, float distance, @Nullable String category) { + public LocationSoundPacket(UUID channelId, UUID sender, Position location, byte[] data, long sequenceNumber, float distance, @Nullable String category) { super(channelId, sender, data, sequenceNumber, category); this.location = location; this.distance = distance; } - public LocationSoundPacket(UUID channelId, UUID sender, short[] data, Vec3 location, float distance, @Nullable String category) { + public LocationSoundPacket(UUID channelId, UUID sender, short[] data, Position location, float distance, @Nullable String category) { super(channelId, sender, data, category); this.location = location; this.distance = distance; @@ -27,7 +28,7 @@ public LocationSoundPacket() { } - public Vec3 getLocation() { + public Position getLocation() { return location; } @@ -36,31 +37,31 @@ public float getDistance() { } @Override - public LocationSoundPacket fromBytes(FriendlyByteBuf buf) { + public LocationSoundPacket fromBytes(ByteBuf buf) { LocationSoundPacket soundPacket = new LocationSoundPacket(); - soundPacket.channelId = buf.readUUID(); - soundPacket.sender = buf.readUUID(); - soundPacket.location = new Vec3(buf.readDouble(), buf.readDouble(), buf.readDouble()); - soundPacket.data = buf.readByteArray(); + soundPacket.channelId = BufferUtils.readUUID(buf); + soundPacket.sender = BufferUtils.readUUID(buf); + soundPacket.location = CommonCompatibilityManager.INSTANCE.createPosition(buf.readDouble(), buf.readDouble(), buf.readDouble()); + soundPacket.data = BufferUtils.readByteArray(buf); soundPacket.sequenceNumber = buf.readLong(); soundPacket.distance = buf.readFloat(); byte data = buf.readByte(); if (hasFlag(data, HAS_CATEGORY_MASK)) { - soundPacket.category = buf.readUtf(16); + soundPacket.category = BufferUtils.readUtf(buf, 16); } return soundPacket; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(channelId); - buf.writeUUID(sender); - buf.writeDouble(location.x); - buf.writeDouble(location.y); - buf.writeDouble(location.z); - buf.writeByteArray(data); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, channelId); + BufferUtils.writeUUID(buf, sender); + buf.writeDouble(location.getX()); + buf.writeDouble(location.getY()); + buf.writeDouble(location.getZ()); + BufferUtils.writeByteArray(buf, data); buf.writeLong(sequenceNumber); buf.writeFloat(distance); @@ -70,7 +71,7 @@ public void toBytes(FriendlyByteBuf buf) { } buf.writeByte(data); if (category != null) { - buf.writeUtf(category, 16); + BufferUtils.writeUtf(buf, category, 16); } } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/MicPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/MicPacket.java similarity index 82% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/MicPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/MicPacket.java index 393776805..f2052d372 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/MicPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/MicPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; public class MicPacket implements Packet { @@ -40,17 +40,17 @@ public boolean isWhispering() { } @Override - public MicPacket fromBytes(FriendlyByteBuf buf) { + public MicPacket fromBytes(ByteBuf buf) { MicPacket soundPacket = new MicPacket(); - soundPacket.data = buf.readByteArray(); + soundPacket.data = BufferUtils.readByteArray(buf); soundPacket.sequenceNumber = buf.readLong(); soundPacket.whispering = buf.readBoolean(); return soundPacket; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeByteArray(data); + public void toBytes(ByteBuf buf) { + BufferUtils.writeByteArray(buf, data); buf.writeLong(sequenceNumber); buf.writeBoolean(whispering); } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/NamedThreadPoolFactory.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/NamedThreadPoolFactory.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/NamedThreadPoolFactory.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/NamedThreadPoolFactory.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/NetworkMessage.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/NetworkMessage.java similarity index 92% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/NetworkMessage.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/NetworkMessage.java index 5030b9878..20ba9bfcf 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/NetworkMessage.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/NetworkMessage.java @@ -6,7 +6,7 @@ import de.maxhenkel.voicechat.voice.server.ClientConnection; import de.maxhenkel.voicechat.voice.server.Server; import io.netty.buffer.Unpooled; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -80,12 +80,12 @@ public SocketAddress getAddress() { @Nullable public static NetworkMessage readPacketServer(RawUdpPacket packet, Server server) throws IllegalAccessException, InstantiationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, InvocationTargetException, NoSuchMethodException { byte[] data = packet.getData(); - FriendlyByteBuf b = new FriendlyByteBuf(Unpooled.wrappedBuffer(data)); + ByteBuf b = Unpooled.wrappedBuffer(data); if (b.readByte() != MAGIC_BYTE) { Voicechat.LOGGER.debug("Received invalid packet from {}", packet.getSocketAddress()); return null; } - UUID playerID = b.readUUID(); + UUID playerID = BufferUtils.readUUID(b); if (!server.hasSecret(playerID)) { if (PingHandler.onPacket(server, packet.getSocketAddress(), playerID, b)) { return null; @@ -94,7 +94,7 @@ public static NetworkMessage readPacketServer(RawUdpPacket packet, Server server Voicechat.LOGGER.debug("Player {} does not have a secret", playerID); return null; } - return readFromBytes(packet.getSocketAddress(), server.getSecret(playerID), b.readByteArray(), packet.getTimestamp()); + return readFromBytes(packet.getSocketAddress(), server.getSecret(playerID), BufferUtils.readByteArray(b), packet.getTimestamp()); } @Nullable @@ -107,7 +107,7 @@ public static NetworkMessage readFromBytes(SocketAddress socketAddress, Secret s Voicechat.LOGGER.debug("Failed to decrypt packet from {}", socketAddress); return null; } - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.wrappedBuffer(decrypt)); + ByteBuf buffer = Unpooled.wrappedBuffer(decrypt); byte packetType = buffer.readByte(); Class packetClass = packetRegistry.get(packetType); if (packetClass == null) { @@ -134,9 +134,9 @@ private static byte getPacketType(Packet packet) { public byte[] writeServer(Server server, ClientConnection connection) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { byte[] payload = write(server.getSecret(connection.getPlayerUUID())); - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer(1 + payload.length)); + ByteBuf buffer = Unpooled.buffer(1 + payload.length); buffer.writeByte(MAGIC_BYTE); - buffer.writeByteArray(payload); + BufferUtils.writeByteArray(buffer, payload); byte[] bytes = new byte[buffer.readableBytes()]; buffer.readBytes(bytes); @@ -144,7 +144,7 @@ public byte[] writeServer(Server server, ClientConnection connection) throws Inv } public byte[] write(Secret secret) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()); + ByteBuf buffer = Unpooled.buffer(); byte type = getPacketType(packet); if (type < 0) { diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/Packet.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/Packet.java similarity index 55% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/Packet.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/Packet.java index ec53e436f..098e2c003 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/Packet.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/Packet.java @@ -1,12 +1,12 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; public interface Packet { - T fromBytes(FriendlyByteBuf buf); + T fromBytes(ByteBuf buf); - void toBytes(FriendlyByteBuf buf); + void toBytes(ByteBuf buf); default long getTTL() { return 10_000L; diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/PingPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/PingPacket.java similarity index 75% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/PingPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/PingPacket.java index d0aac693c..4233f4ba9 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/PingPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/PingPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import java.util.UUID; @@ -27,16 +27,16 @@ public UUID getId() { } @Override - public PingPacket fromBytes(FriendlyByteBuf buf) { + public PingPacket fromBytes(ByteBuf buf) { PingPacket soundPacket = new PingPacket(); - soundPacket.id = buf.readUUID(); + soundPacket.id = BufferUtils.readUUID(buf); soundPacket.timestamp = buf.readLong(); return soundPacket; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(id); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, id); buf.writeLong(timestamp); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerSoundPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerSoundPacket.java similarity index 76% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerSoundPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerSoundPacket.java index 7166032a2..5bd883079 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerSoundPacket.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerSoundPacket.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import javax.annotation.Nullable; import java.util.UUID; @@ -39,27 +39,27 @@ public float getDistance() { } @Override - public PlayerSoundPacket fromBytes(FriendlyByteBuf buf) { + public PlayerSoundPacket fromBytes(ByteBuf buf) { PlayerSoundPacket soundPacket = new PlayerSoundPacket(); - soundPacket.channelId = buf.readUUID(); - soundPacket.sender = buf.readUUID(); - soundPacket.data = buf.readByteArray(); + soundPacket.channelId = BufferUtils.readUUID(buf); + soundPacket.sender = BufferUtils.readUUID(buf); + soundPacket.data = BufferUtils.readByteArray(buf); soundPacket.sequenceNumber = buf.readLong(); soundPacket.distance = buf.readFloat(); byte data = buf.readByte(); soundPacket.whispering = hasFlag(data, WHISPER_MASK); if (hasFlag(data, HAS_CATEGORY_MASK)) { - soundPacket.category = buf.readUtf(16); + soundPacket.category = BufferUtils.readUtf(buf, 16); } return soundPacket; } @Override - public void toBytes(FriendlyByteBuf buf) { - buf.writeUUID(channelId); - buf.writeUUID(sender); - buf.writeByteArray(data); + public void toBytes(ByteBuf buf) { + BufferUtils.writeUUID(buf, channelId); + BufferUtils.writeUUID(buf, sender); + BufferUtils.writeByteArray(buf, data); buf.writeLong(sequenceNumber); buf.writeFloat(distance); @@ -72,7 +72,7 @@ public void toBytes(FriendlyByteBuf buf) { } buf.writeByte(data); if (category != null) { - buf.writeUtf(category, 16); + BufferUtils.writeUtf(buf, category, 16); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerState.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerState.java similarity index 83% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerState.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerState.java index c60683a10..1b5477987 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerState.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/PlayerState.java @@ -1,6 +1,6 @@ package de.maxhenkel.voicechat.voice.common; -import net.minecraft.network.FriendlyByteBuf; +import io.netty.buffer.ByteBuf; import javax.annotation.Nullable; import java.util.UUID; @@ -77,29 +77,29 @@ public String toString() { '}'; } - public static PlayerState fromBytes(FriendlyByteBuf buf) { + public static PlayerState fromBytes(ByteBuf buf) { boolean disabled = buf.readBoolean(); boolean disconnected = buf.readBoolean(); - UUID uuid = buf.readUUID(); - String name = buf.readUtf(32767); + UUID uuid = BufferUtils.readUUID(buf); + String name = BufferUtils.readUtf(buf); PlayerState state = new PlayerState(uuid, name, disabled, disconnected); if (buf.readBoolean()) { - state.setGroup(buf.readUUID()); + state.setGroup(BufferUtils.readUUID(buf)); } return state; } - public void toBytes(FriendlyByteBuf buf) { + public void toBytes(ByteBuf buf) { buf.writeBoolean(disabled); buf.writeBoolean(disconnected); - buf.writeUUID(uuid); - buf.writeUtf(name); + BufferUtils.writeUUID(buf, uuid); + BufferUtils.writeUtf(buf, name); buf.writeBoolean(hasGroup()); if (hasGroup()) { - buf.writeUUID(group); + BufferUtils.writeUUID(buf, group); } } diff --git a/core/src/main/java/de/maxhenkel/voicechat/voice/common/ResourceLocation.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ResourceLocation.java new file mode 100644 index 000000000..9cd131578 --- /dev/null +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/ResourceLocation.java @@ -0,0 +1,4 @@ +package de.maxhenkel.voicechat.voice.common; + +public record ResourceLocation(String key, String value) { +} diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/Secret.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/Secret.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/Secret.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/Secret.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/common/SoundPacket.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/SoundPacket.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/common/SoundPacket.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/common/SoundPacket.java diff --git a/core/src/main/java/de/maxhenkel/voicechat/voice/common/Utils.java b/core/src/main/java/de/maxhenkel/voicechat/voice/common/Utils.java new file mode 100644 index 000000000..b989f55b2 --- /dev/null +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/common/Utils.java @@ -0,0 +1,39 @@ +package de.maxhenkel.voicechat.voice.common; + +import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.api.Position; + +public class Utils { + + public static void sleep(int ms) { + try { + Thread.sleep(ms); + } catch (InterruptedException ex) { + } + } + + public static float normalizeAngle(float angle) { + angle = angle % 360F; + if (angle <= -180F) { + angle += 360F; + } else if (angle > 180F) { + angle -= 360F; + } + return angle; + } + + public static float angle(float vec1x, float vec2x, float vec1y, float vec2y) { + return (float) Math.toDegrees(Math.atan2(vec1x * vec2x + vec1y * vec2y, vec1x * vec2y - vec1y * vec2x)); + } + + public static float getDefaultDistanceServer() { + return Voicechat.SERVER_CONFIG.voiceChatDistance.get().floatValue(); + } + + public static double distanceToSqr(Position vec3, Position vec32) { + double d = vec32.getX() - vec3.getX(); + double e = vec32.getY() - vec3.getY(); + double f = vec32.getZ() - vec3.getZ(); + return d * d + e * e + f * f; + } +} diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ClientConnection.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ClientConnection.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/ClientConnection.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/ClientConnection.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/Group.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/Group.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/Group.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/Group.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/PingManager.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/PingManager.java similarity index 100% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/PingManager.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/PingManager.java diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/PlayerStateManager.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/PlayerStateManager.java similarity index 82% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/PlayerStateManager.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/PlayerStateManager.java index 701b7c97d..950137702 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/server/PlayerStateManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/server/PlayerStateManager.java @@ -8,7 +8,7 @@ import de.maxhenkel.voicechat.net.RemovePlayerStatePacket; import de.maxhenkel.voicechat.plugins.PluginManager; import de.maxhenkel.voicechat.voice.common.PlayerState; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.ServerPlayer; import javax.annotation.Nullable; import java.util.ArrayList; @@ -27,7 +27,7 @@ public PlayerStateManager(Server voicechatServer) { this.states = new ConcurrentHashMap<>(); CommonCompatibilityManager.INSTANCE.getNetManager().updateStateChannel.setServerListener((server, player, handler, packet) -> { - PlayerState state = states.get(player.getUUID()); + PlayerState state = states.get(player.getUuid()); if (state == null) { state = defaultDisconnectedState(player); @@ -35,16 +35,16 @@ public PlayerStateManager(Server voicechatServer) { state.setDisabled(packet.isDisabled()); - states.put(player.getUUID(), state); + states.put(player.getUuid(), state); broadcastState(player, state); - Voicechat.LOGGER.debug("Got state of {}: {}", player.getName().getString(), state); + Voicechat.LOGGER.debug("Got state of {}: {}", player.getName(), state); }); } public void broadcastState(@Nullable ServerPlayer stateOwner, PlayerState state) { PlayerStatePacket packet = new PlayerStatePacket(state); - for (ServerPlayer receiver : voicechatServer.getServer().getPlayerList().getPlayers()) { + for (ServerPlayer receiver : voicechatServer.getServer().getPlayers()) { if (stateOwner != null && !CommonCompatibilityManager.INSTANCE.canSee(receiver, stateOwner)) { continue; } @@ -54,8 +54,8 @@ public void broadcastState(@Nullable ServerPlayer stateOwner, PlayerState state) } public void broadcastRemoveState(ServerPlayer stateOwner) { - RemovePlayerStatePacket packet = new RemovePlayerStatePacket(stateOwner.getUUID()); - for (ServerPlayer receiver : voicechatServer.getServer().getPlayerList().getPlayers()) { + RemovePlayerStatePacket packet = new RemovePlayerStatePacket(stateOwner.getUuid()); + for (ServerPlayer receiver : voicechatServer.getServer().getPlayers()) { NetManager.sendToClient(receiver, packet); } // Send the default disconnected state to the API when disconnecting @@ -65,7 +65,7 @@ public void broadcastRemoveState(ServerPlayer stateOwner) { public void onPlayerCompatibilityCheckSucceeded(ServerPlayer player) { List stateList = new ArrayList<>(states.size()); for (PlayerState state : states.values()) { - ServerPlayer otherPlayer = voicechatServer.getServer().getPlayerList().getPlayer(state.getUuid()); + ServerPlayer otherPlayer = voicechatServer.getServer().getPlayer(state.getUuid()); if (otherPlayer == null) { continue; } @@ -76,36 +76,36 @@ public void onPlayerCompatibilityCheckSucceeded(ServerPlayer player) { } PlayerStatesPacket packet = new PlayerStatesPacket(stateList); NetManager.sendToClient(player, packet); - Voicechat.LOGGER.debug("Sending initial states to {}", player.getName().getString()); + Voicechat.LOGGER.debug("Sending initial states to {}", player.getName()); } public void onPlayerLoggedIn(ServerPlayer player) { PlayerState state = defaultDisconnectedState(player); - states.put(player.getUUID(), state); + states.put(player.getUuid(), state); broadcastState(player, state); - Voicechat.LOGGER.debug("Setting default state of {}: {}", player.getName().getString(), state); + Voicechat.LOGGER.debug("Setting default state of {}: {}", player.getName(), state); } public void onPlayerLoggedOut(ServerPlayer player) { - states.remove(player.getUUID()); + states.remove(player.getUuid()); broadcastRemoveState(player); - Voicechat.LOGGER.debug("Removing state of {}", player.getName().getString()); + Voicechat.LOGGER.debug("Removing state of {}", player.getName()); } public void onPlayerHide(ServerPlayer visibilityChangedPlayer, ServerPlayer observingPlayer) { - RemovePlayerStatePacket packet = new RemovePlayerStatePacket(visibilityChangedPlayer.getUUID()); + RemovePlayerStatePacket packet = new RemovePlayerStatePacket(visibilityChangedPlayer.getUuid()); NetManager.sendToClient(observingPlayer, packet); - Voicechat.LOGGER.debug("Removing state of {} for {}", visibilityChangedPlayer.getName().getString(), observingPlayer.getName().getString()); + Voicechat.LOGGER.debug("Removing state of {} for {}", visibilityChangedPlayer.getName(), observingPlayer.getName()); } public void onPlayerShow(ServerPlayer visibilityChangedPlayer, ServerPlayer observingPlayer) { - PlayerState state = states.get(visibilityChangedPlayer.getUUID()); + PlayerState state = states.get(visibilityChangedPlayer.getUuid()); if (state == null) { state = defaultDisconnectedState(visibilityChangedPlayer); } PlayerStatePacket packet = new PlayerStatePacket(state); NetManager.sendToClient(observingPlayer, packet); - Voicechat.LOGGER.debug("Sending state of {} to {}", visibilityChangedPlayer.getName().getString(), observingPlayer.getName().getString()); + Voicechat.LOGGER.debug("Sending state of {} to {}", visibilityChangedPlayer.getName(), observingPlayer.getName()); } public void onPlayerVoicechatDisconnect(UUID uuid) { @@ -116,14 +116,14 @@ public void onPlayerVoicechatDisconnect(UUID uuid) { state.setDisconnected(true); - @Nullable ServerPlayer player = voicechatServer.getServer().getPlayerList().getPlayer(uuid); + @Nullable ServerPlayer player = voicechatServer.getServer().getPlayer(uuid); broadcastState(player, state); Voicechat.LOGGER.debug("Set state of {} to disconnected: {}", uuid, state); } public void onPlayerVoicechatConnect(ServerPlayer player) { - PlayerState state = states.get(player.getUUID()); + PlayerState state = states.get(player.getUuid()); if (state == null) { state = defaultDisconnectedState(player); @@ -131,10 +131,10 @@ public void onPlayerVoicechatConnect(ServerPlayer player) { state.setDisconnected(false); - states.put(player.getUUID(), state); + states.put(player.getUuid(), state); broadcastState(player, state); - Voicechat.LOGGER.debug("Set state of {} to connected: {}", player.getName().getString(), state); + Voicechat.LOGGER.debug("Set state of {} to connected: {}", player.getName(), state); } @Nullable @@ -143,19 +143,19 @@ public PlayerState getState(UUID playerUUID) { } public static PlayerState defaultDisconnectedState(ServerPlayer player) { - return new PlayerState(player.getUUID(), player.getGameProfile().getName(), false, true); + return new PlayerState(player.getUuid(), player.getName(), false, true); } public void setGroup(ServerPlayer player, @Nullable UUID group) { - PlayerState state = states.get(player.getUUID()); + PlayerState state = states.get(player.getUuid()); if (state == null) { state = PlayerStateManager.defaultDisconnectedState(player); - Voicechat.LOGGER.debug("Defaulting to default state for {}: {}", player.getName().getString(), state); + Voicechat.LOGGER.debug("Defaulting to default state for {}: {}", player.getName(), state); } state.setGroup(group); - states.put(player.getUUID(), state); + states.put(player.getUuid(), state); broadcastState(player, state); - Voicechat.LOGGER.debug("Setting group of {}: {}", player.getName().getString(), state); + Voicechat.LOGGER.debug("Setting group of {}: {}", player.getName(), state); } public Collection getStates() { diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/Server.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/Server.java similarity index 91% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/Server.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/Server.java index be367dc6a..c90998272 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/server/Server.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/server/Server.java @@ -10,11 +10,8 @@ import de.maxhenkel.voicechat.permission.PermissionManager; import de.maxhenkel.voicechat.plugins.PluginManager; import de.maxhenkel.voicechat.voice.common.*; -import net.minecraft.network.chat.Component; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import javax.annotation.Nullable; import java.net.InetAddress; @@ -34,7 +31,6 @@ public class Server extends Thread { private final Map connections; private final Map unCheckedConnections; private final Map secrets; - private final boolean dedicated; private int port; private final MinecraftServer server; private VoicechatSocket socket; @@ -46,8 +42,7 @@ public class Server extends Thread { private final ServerCategoryManager categoryManager; public Server(MinecraftServer server) { - dedicated = server instanceof DedicatedServer; - if (dedicated) { + if (server.isDedicated()) { int configPort = Voicechat.SERVER_CONFIG.voiceChatPort.get(); if (configPort < 0) { Voicechat.LOGGER.info("Using the Minecraft servers port as voice chat port"); @@ -80,7 +75,7 @@ public void onPlayerLoggedIn(ServerPlayer player) { } public void onPlayerLoggedOut(ServerPlayer player) { - this.disconnectClient(player.getUUID()); + this.disconnectClient(player.getUuid()); playerStateManager.onPlayerLoggedOut(player); groupManager.onPlayerLoggedOut(player); } @@ -144,7 +139,7 @@ public void run() { } private String getBindAddress() { - if (!dedicated) { + if (!server.isDedicated()) { return ""; } @@ -153,8 +148,8 @@ private String getBindAddress() { if (bindAddress.trim().equals("*")) { bindAddress = ""; } else if (bindAddress.trim().equals("")) { - if (server instanceof DedicatedServer) { - bindAddress = ((DedicatedServer) server).getProperties().serverIp; + if (server.isDedicated()) { + bindAddress = server.getIp(); if (!bindAddress.trim().isEmpty()) { try { InetAddress address = InetAddress.getByName(bindAddress); @@ -316,11 +311,11 @@ public void run() { connections.put(connection.getPlayerUUID(), connection); unCheckedConnections.remove(connection.getPlayerUUID()); Voicechat.LOGGER.info("Successfully validated connection of player {}", connection.getPlayerUUID()); - ServerPlayer player = server.getPlayerList().getPlayer(connection.getPlayerUUID()); + ServerPlayer player = server.getPlayer(connection.getPlayerUUID()); if (player != null) { CommonCompatibilityManager.INSTANCE.emitServerVoiceChatConnectedEvent(player); PluginManager.instance().onPlayerConnected(player); - Voicechat.LOGGER.info("Player {} ({}) successfully connected to voice chat", player.getName().getString(), connection.getPlayerUUID()); + Voicechat.LOGGER.info("Player {} ({}) successfully connected to voice chat", player.getName(), connection.getPlayerUUID()); } sendPacket(new ConnectionCheckAckPacket(), connection); continue; @@ -350,17 +345,17 @@ public void close() { } public void onMicPacket(UUID playerUuid, MicPacket packet) { - ServerPlayer player = server.getPlayerList().getPlayer(playerUuid); + ServerPlayer player = server.getPlayer(playerUuid); if (player == null) { return; } if (!PermissionManager.INSTANCE.SPEAK_PERMISSION.hasPermission(player)) { - CooldownTimer.run("no-speak-" + playerUuid, 30_000L, () -> { - player.displayClientMessage(Component.translatable("message.voicechat.no_speak_permission"), true); + CooldownTimer.run("no-speak-" + player.getUuid(), 30_000L, () -> { + CommonCompatibilityManager.INSTANCE.displayClientMessage(player, "message.voicechat.no_speak_permission", true); }); return; } - PlayerState state = playerStateManager.getState(player.getUUID()); + PlayerState state = playerStateManager.getState(player.getUuid()); if (state == null) { return; } @@ -394,7 +389,7 @@ private void processGroupPacket(PlayerState senderState, ServerPlayer sender, Mi if (senderState.getUuid().equals(state.getUuid())) { continue; } - ServerPlayer p = server.getPlayerList().getPlayer(state.getUuid()); + ServerPlayer p = server.getPlayer(state.getUuid()); if (p == null) { continue; } @@ -418,10 +413,10 @@ private void processProximityPacket(PlayerState senderState, ServerPlayer sender String source = null; if (sender.isSpectator()) { if (Voicechat.SERVER_CONFIG.spectatorPlayerPossession.get()) { - Entity camera = sender.getCamera(); - if (camera instanceof ServerPlayer spectatingPlayer) { + ServerPlayer spectatingPlayer = sender.getCameraPlayer(); + if (spectatingPlayer != null) { if (spectatingPlayer != sender) { - PlayerState receiverState = playerStateManager.getState(spectatingPlayer.getUUID()); + PlayerState receiverState = playerStateManager.getState(spectatingPlayer.getUuid()); if (receiverState == null) { return; } @@ -433,21 +428,21 @@ private void processProximityPacket(PlayerState senderState, ServerPlayer sender } } if (Voicechat.SERVER_CONFIG.spectatorInteraction.get()) { - soundPacket = new LocationSoundPacket(sender.getUUID(), sender.getUUID(), sender.getEyePosition(), packet.getData(), packet.getSequenceNumber(), distance, null); + soundPacket = new LocationSoundPacket(sender.getUuid(), sender.getUuid(), sender.getEyePosition(), packet.getData(), packet.getSequenceNumber(), distance, null); source = SoundPacketEvent.SOURCE_SPECTATOR; } } if (soundPacket == null) { - soundPacket = new PlayerSoundPacket(sender.getUUID(), sender.getUUID(), packet.getData(), packet.getSequenceNumber(), packet.isWhispering(), distance, null); + soundPacket = new PlayerSoundPacket(sender.getUuid(), sender.getUuid(), packet.getData(), packet.getSequenceNumber(), packet.isWhispering(), distance, null); source = SoundPacketEvent.SOURCE_PROXIMITY; } - broadcast(ServerWorldUtils.getPlayersInRange(sender.serverLevel(), sender.position(), getBroadcastRange(distance), p -> !p.getUUID().equals(sender.getUUID())), soundPacket, sender, senderState, groupId, source); + broadcast(ServerWorldUtils.getPlayersInRange(sender.getLevel(), sender.getPosition(), getBroadcastRange(distance), p -> !p.getUuid().equals(sender.getUuid())), soundPacket, sender, senderState, groupId, source); } public void sendSoundPacket(@Nullable ServerPlayer sender, @Nullable PlayerState senderState, ServerPlayer receiver, PlayerState receiverState, @Nullable ClientConnection connection, SoundPacket soundPacket, String source) { - PluginManager.instance().onListenerAudio(receiver.getUUID(), soundPacket); + PluginManager.instance().onListenerAudio(receiver.getUuid(), soundPacket); if (connection == null) { return; @@ -462,8 +457,8 @@ public void sendSoundPacket(@Nullable ServerPlayer sender, @Nullable PlayerState } if (!PermissionManager.INSTANCE.LISTEN_PERMISSION.hasPermission(receiver)) { - CooldownTimer.run(String.format("no-listen-%s", receiver.getUUID()), 30_000L, () -> { - receiver.displayClientMessage(Component.translatable("message.voicechat.no_listen_permission"), true); + CooldownTimer.run(String.format("no-listen-%s", receiver.getUuid()), 30_000L, () -> { + CommonCompatibilityManager.INSTANCE.displayClientMessage(receiver, "message.voicechat.no_listen_permission", true); }); return; } @@ -480,7 +475,7 @@ public double getBroadcastRange(float minRange) { public void broadcast(Collection players, SoundPacket packet, @Nullable ServerPlayer sender, @Nullable PlayerState senderState, @Nullable UUID groupId, String source) { for (ServerPlayer player : players) { - PlayerState state = playerStateManager.getState(player.getUUID()); + PlayerState state = playerStateManager.getState(player.getUuid()); if (state == null) { continue; } @@ -507,9 +502,9 @@ private void sendKeepAlives() { // Don't call disconnectClient here! secrets.remove(connection.getPlayerUUID()); Voicechat.LOGGER.info("Player {} timed out", connection.getPlayerUUID()); - ServerPlayer player = server.getPlayerList().getPlayer(connection.getPlayerUUID()); + ServerPlayer player = server.getPlayer(connection.getPlayerUUID()); if (player != null) { - Voicechat.LOGGER.info("Reconnecting player {}", player.getName().getString()); + Voicechat.LOGGER.info("Reconnecting player {}", player.getName()); Voicechat.SERVER.initializePlayerConnection(player); } else { Voicechat.LOGGER.warn("Reconnecting player {} failed (Could not find player)", connection.getPlayerUUID()); diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerCategoryManager.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerCategoryManager.java similarity index 81% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerCategoryManager.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerCategoryManager.java index 8a960b959..0f995c4b9 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerCategoryManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerCategoryManager.java @@ -1,14 +1,13 @@ package de.maxhenkel.voicechat.voice.server; import de.maxhenkel.voicechat.Voicechat; -import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import de.maxhenkel.voicechat.net.AddCategoryPacket; import de.maxhenkel.voicechat.net.NetManager; import de.maxhenkel.voicechat.net.RemoveCategoryPacket; import de.maxhenkel.voicechat.plugins.CategoryManager; import de.maxhenkel.voicechat.plugins.impl.VolumeCategoryImpl; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; import javax.annotation.Nullable; @@ -21,7 +20,7 @@ public ServerCategoryManager(Server server) { } public void onPlayerCompatibilityCheckSucceeded(ServerPlayer player) { - Voicechat.LOGGER.debug("Synchronizing {} volume categories with {}", categories.size(), player.getName().getString()); + Voicechat.LOGGER.debug("Synchronizing {} volume categories with {}", categories.size(), player.getName()); for (VolumeCategoryImpl category : getCategories()) { broadcastAddCategory(server.getServer(), category); } @@ -45,12 +44,12 @@ public VolumeCategoryImpl removeCategory(String categoryId) { private void broadcastAddCategory(MinecraftServer server, VolumeCategoryImpl category) { AddCategoryPacket packet = new AddCategoryPacket(category); - server.getPlayerList().getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); + server.getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); } private void broadcastRemoveCategory(MinecraftServer server, String categoryId) { RemoveCategoryPacket packet = new RemoveCategoryPacket(categoryId); - server.getPlayerList().getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); + server.getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); } } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerGroupManager.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerGroupManager.java similarity index 89% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerGroupManager.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerGroupManager.java index 84f4093a9..9efa0e3e6 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerGroupManager.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerGroupManager.java @@ -1,6 +1,7 @@ package de.maxhenkel.voicechat.voice.server; import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.api.ServerPlayer; import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; import de.maxhenkel.voicechat.net.AddGroupPacket; import de.maxhenkel.voicechat.net.JoinedGroupPacket; @@ -9,8 +10,6 @@ import de.maxhenkel.voicechat.permission.PermissionManager; import de.maxhenkel.voicechat.plugins.PluginManager; import de.maxhenkel.voicechat.voice.common.PlayerState; -import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerPlayer; import javax.annotation.Nullable; import java.util.List; @@ -32,7 +31,7 @@ public ServerGroupManager(Server server) { return; } if (!PermissionManager.INSTANCE.GROUPS_PERMISSION.hasPermission(player)) { - player.displayClientMessage(Component.translatable("message.voicechat.no_group_permission"), true); + CommonCompatibilityManager.INSTANCE.displayClientMessage(player, "message.voicechat.no_group_permission", true); return; } joinGroup(groups.get(packet.getGroup()), player, packet.getPassword()); @@ -42,11 +41,11 @@ public ServerGroupManager(Server server) { return; } if (!PermissionManager.INSTANCE.GROUPS_PERMISSION.hasPermission(player)) { - player.displayClientMessage(Component.translatable("message.voicechat.no_group_permission"), true); + CommonCompatibilityManager.INSTANCE.displayClientMessage(player, "message.voicechat.no_group_permission", true); return; } if (!Voicechat.GROUP_REGEX.matcher(packet.getName()).matches()) { - Voicechat.LOGGER.warn("Player {} tried to create a group with an invalid name: {}", player.getName().getString(), packet.getName()); + Voicechat.LOGGER.warn("Player {} tried to create a group with an invalid name: {}", player.getName(), packet.getName()); return; } addGroup(new Group(UUID.randomUUID(), packet.getName(), packet.getPassword(), false, false, packet.getType()), player); @@ -57,7 +56,7 @@ public ServerGroupManager(Server server) { } public void onPlayerCompatibilityCheckSucceeded(ServerPlayer player) { - Voicechat.LOGGER.debug("Synchronizing {} groups with {}", groups.size(), player.getName().getString()); + Voicechat.LOGGER.debug("Synchronizing {} groups with {}", groups.size(), player.getName()); for (Group category : groups.values()) { broadcastAddGroup(category); } @@ -158,17 +157,17 @@ public Group getGroup(UUID groupID) { private void broadcastAddGroup(Group group) { AddGroupPacket packet = new AddGroupPacket(group.toClientGroup()); - server.getServer().getPlayerList().getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); + server.getServer().getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); } private void broadcastRemoveGroup(UUID group) { RemoveGroupPacket packet = new RemoveGroupPacket(group); - server.getServer().getPlayerList().getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); + server.getServer().getPlayers().forEach(p -> NetManager.sendToClient(p, packet)); } @Nullable public Group getPlayerGroup(ServerPlayer player) { - PlayerState state = server.getPlayerStateManager().getState(player.getUUID()); + PlayerState state = server.getPlayerStateManager().getState(player.getUuid()); if (state == null) { return null; } diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerVoiceEvents.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerVoiceEvents.java similarity index 65% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerVoiceEvents.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerVoiceEvents.java index 913a272b5..19e07ad5d 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerVoiceEvents.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerVoiceEvents.java @@ -1,6 +1,5 @@ package de.maxhenkel.voicechat.voice.server; -import de.maxhenkel.voicechat.BuildConstants; import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; import de.maxhenkel.voicechat.intercompatibility.CrossSideManager; @@ -8,16 +7,11 @@ import de.maxhenkel.voicechat.net.SecretPacket; import de.maxhenkel.voicechat.plugins.PluginManager; import de.maxhenkel.voicechat.voice.common.Secret; -import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.Component; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import javax.annotation.Nullable; import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -40,30 +34,19 @@ public ServerVoiceEvents() { CommonCompatibilityManager.INSTANCE.onPlayerCompatibilityCheckSucceeded(this::playerCompatibilityCheckSucceeded); CommonCompatibilityManager.INSTANCE.getNetManager().requestSecretChannel.setServerListener((server, player, handler, packet) -> { - Voicechat.LOGGER.info("Received secret request of {} ({})", player.getName().getString(), packet.getCompatibilityVersion()); - clientCompatibilities.put(player.getUUID(), packet.getCompatibilityVersion()); + Voicechat.LOGGER.info("Received secret request of {} ({})", player.getName(), packet.getCompatibilityVersion()); + clientCompatibilities.put(player.getUuid(), packet.getCompatibilityVersion()); if (packet.getCompatibilityVersion() != Voicechat.COMPATIBILITY_VERSION) { - Voicechat.LOGGER.warn("Connected client {} has incompatible voice chat version (server={}, client={})", player.getName().getString(), Voicechat.COMPATIBILITY_VERSION, packet.getCompatibilityVersion()); - player.sendSystemMessage(getIncompatibleMessage(packet.getCompatibilityVersion())); + Voicechat.LOGGER.warn("Connected client {} has incompatible voice chat version (server={}, client={})", player.getName(), Voicechat.COMPATIBILITY_VERSION, packet.getCompatibilityVersion()); + CommonCompatibilityManager.INSTANCE.sendIncompatibleMessage(player, packet.getCompatibilityVersion()); } else { initializePlayerConnection(player); } }); } - public Component getIncompatibleMessage(int clientCompatibilityVersion) { - if (clientCompatibilityVersion <= 6) { - return Component.literal(Voicechat.TRANSLATIONS.voicechatNotCompatibleMessage.get().formatted(BuildConstants.MOD_COMPATIBLE_VERSION, CommonCompatibilityManager.INSTANCE.getModName())); - } else { - return Component.translatableWithFallback("message.voicechat.incompatible_version", - "Your voice chat client version is not compatible with the server-side version.\nPlease install version %s of %s.", - Component.literal(BuildConstants.MOD_COMPATIBLE_VERSION).withStyle(ChatFormatting.BOLD), - Component.literal(CommonCompatibilityManager.INSTANCE.getModName()).withStyle(ChatFormatting.BOLD)); - } - } - public boolean isCompatible(ServerPlayer player) { - return isCompatible(player.getUUID()); + return isCompatible(player.getUuid()); } public boolean isCompatible(UUID playerUuid) { @@ -81,7 +64,7 @@ public void serverStarting(MinecraftServer mcServer) { return; } - if (mcServer instanceof DedicatedServer) { + if (mcServer.isDedicated()) { if (!mcServer.usesAuthentication()) { Voicechat.LOGGER.warn("Running in offline mode - Voice chat encryption is not secure!"); } @@ -102,13 +85,13 @@ public void initializePlayerConnection(ServerPlayer player) { } CommonCompatibilityManager.INSTANCE.emitPlayerCompatibilityCheckSucceeded(player); - Secret secret = server.generateNewSecret(player.getUUID()); + Secret secret = server.generateNewSecret(player.getUuid()); if (secret == null) { Voicechat.LOGGER.warn("Player already requested secret - ignoring"); return; } NetManager.sendToClient(player, new SecretPacket(player, secret, server.getPort(), Voicechat.SERVER_CONFIG)); - Voicechat.LOGGER.info("Sent secret to {}", player.getName().getString()); + Voicechat.LOGGER.info("Sent secret to {}", player.getName()); } public void playerLoggedIn(ServerPlayer serverPlayer) { @@ -120,39 +103,17 @@ public void playerLoggedIn(ServerPlayer serverPlayer) { return; } - Timer timer = new Timer("%s-login-timer".formatted(serverPlayer.getGameProfile().getName()), true); - timer.schedule(new TimerTask() { - @Override - public void run() { - timer.cancel(); - timer.purge(); - if (!serverPlayer.server.isRunning()) { - return; - } - if (!serverPlayer.connection.isAcceptingMessages()) { - return; - } - if (!isCompatible(serverPlayer)) { - CommonCompatibilityManager.INSTANCE.execute(serverPlayer.server, () -> { - serverPlayer.connection.disconnect( - Component.literal(Voicechat.TRANSLATIONS.forceVoicechatKickMessage.get().formatted( - CommonCompatibilityManager.INSTANCE.getModName(), - CommonCompatibilityManager.INSTANCE.getModVersion() - ))); - }); - } - } - }, Voicechat.SERVER_CONFIG.loginTimeout.get()); + CommonCompatibilityManager.INSTANCE.createTimeoutTimer(serverPlayer); } public void playerLoggedOut(ServerPlayer player) { - clientCompatibilities.remove(player.getUUID()); + clientCompatibilities.remove(player.getUuid()); if (server == null) { return; } server.onPlayerLoggedOut(player); - Voicechat.LOGGER.info("Disconnecting client {}", player.getName().getString()); + Voicechat.LOGGER.info("Disconnecting client {}", player.getName()); } public void onPlayerHide(ServerPlayer visibilityChangedPlayer, ServerPlayer observingPlayer) { diff --git a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerWorldUtils.java b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerWorldUtils.java similarity index 54% rename from common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerWorldUtils.java rename to core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerWorldUtils.java index a504f0095..42f088cfd 100644 --- a/common/src/main/java/de/maxhenkel/voicechat/voice/server/ServerWorldUtils.java +++ b/core/src/main/java/de/maxhenkel/voicechat/voice/server/ServerWorldUtils.java @@ -1,8 +1,9 @@ package de.maxhenkel.voicechat.voice.server; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.phys.Vec3; +import de.maxhenkel.voicechat.api.ServerLevel; +import de.maxhenkel.voicechat.api.ServerPlayer; +import de.maxhenkel.voicechat.api.Position; +import de.maxhenkel.voicechat.voice.common.Utils; import javax.annotation.Nullable; import java.util.ArrayList; @@ -12,20 +13,20 @@ public class ServerWorldUtils { - public static Collection getPlayersInRange(ServerLevel level, Vec3 pos, double range, @Nullable Predicate filter) { + public static Collection getPlayersInRange(ServerLevel level, Position pos, double range, @Nullable Predicate filter) { List nearbyPlayers = new ArrayList<>(); List players = level.players(); for (int i = 0; i < players.size(); i++) { ServerPlayer player = players.get(i); - if (isInRange(player.position(), pos, range) && (filter == null || filter.test(player))) { + if (isInRange(player.getPosition(), pos, range) && (filter == null || filter.test(player))) { nearbyPlayers.add(player); } } return nearbyPlayers; } - public static boolean isInRange(Vec3 pos1, Vec3 pos2, double range) { - return pos1.distanceToSqr(pos2) <= range * range; + public static boolean isInRange(Position pos1, Position pos2, double range) { + return Utils.distanceToSqr(pos1, pos2) <= range * range; } } diff --git a/core/src/template/java/de/maxhenkel/voicechat/BuildConstants.java b/core/src/template/java/de/maxhenkel/voicechat/BuildConstants.java new file mode 100644 index 000000000..d50bf1201 --- /dev/null +++ b/core/src/template/java/de/maxhenkel/voicechat/BuildConstants.java @@ -0,0 +1,24 @@ +package de.maxhenkel.voicechat; + +public class BuildConstants { + + public static final int COMPATIBILITY_VERSION; + public static final String MINECRAFT_VERSION = "${minecraft_version}"; + public static final String MOD_COMPATIBLE_VERSION = "${mod_compatible_version}"; + + static { + String compatibilityVersionString = "${compatibility_version}"; + int compatibilityVersion; + try { + compatibilityVersion = Integer.parseInt(compatibilityVersionString); + } catch (NumberFormatException e1) { + try { + compatibilityVersion = Integer.parseInt(System.getenv("COMPATIBILITY_VERSION")); + } catch (NumberFormatException e2) { + compatibilityVersion = -1; + } + } + COMPATIBILITY_VERSION = compatibilityVersion; + } + +} diff --git a/fabric/api-stub/build.gradle b/fabric/api-stub/build.gradle index af403fc61..1d117de11 100644 --- a/fabric/api-stub/build.gradle +++ b/fabric/api-stub/build.gradle @@ -2,13 +2,17 @@ plugins { id 'maven-publish' } -archivesBaseName = archives_base_name +java { + sourceCompatibility = JavaLanguageVersion.of(8) + targetCompatibility = JavaLanguageVersion.of(8) +} + +base { + archivesName = archives_base_name +} version = project(':api').version group = maven_group -sourceCompatibility = JavaLanguageVersion.of(8) -targetCompatibility = JavaLanguageVersion.of(8) - processResources { filesMatching('fabric.mod.json') { expand 'api_version': version @@ -19,7 +23,7 @@ publishing { publications { voiceChatApi(MavenPublication) { artifactId archives_base_name - artifact(jar.archivePath) { + artifact(jar) { builtBy build classifier 'fabric-stub' } diff --git a/fabric/build.gradle b/fabric/build.gradle index c093570a5..f37339b79 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'fabric-loom' apply plugin: 'com.gradleup.shadow' -apply plugin: 'com.matthewprenger.cursegradle' +apply plugin: 'de.maxhenkel.cursegradle' apply plugin: 'com.modrinth.minotaur' apply plugin: 'mod-update' diff --git a/fabric/changelog.md b/fabric/changelog.md index 07213e8c8..955d330c6 100644 --- a/fabric/changelog.md +++ b/fabric/changelog.md @@ -1 +1 @@ -- Make long text in adjust volumes screen scrollable +- Fixed volume abruptly increasing shortly after starting to speak diff --git a/fabric/gradle.properties b/fabric/gradle.properties index e36ec4b07..b3eca0336 100644 --- a/fabric/gradle.properties +++ b/fabric/gradle.properties @@ -1,6 +1,6 @@ mod_loader=fabric -included_projects=:api, :common, :common-client +included_projects=:api, :core, :common, :common-client minecraft_dependency=1.20.1 diff --git a/fabric/src/main/java/de/maxhenkel/voicechat/integration/vanish/VanishIntegration.java b/fabric/src/main/java/de/maxhenkel/voicechat/integration/vanish/VanishIntegration.java index ff4a159fb..289aec799 100644 --- a/fabric/src/main/java/de/maxhenkel/voicechat/integration/vanish/VanishIntegration.java +++ b/fabric/src/main/java/de/maxhenkel/voicechat/integration/vanish/VanishIntegration.java @@ -3,6 +3,7 @@ import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.events.VanishEvents; import de.maxhenkel.voicechat.intercompatibility.CommonCompatibilityManager; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import me.drex.vanish.api.VanishAPI; import net.minecraft.server.level.ServerPlayer; @@ -38,12 +39,12 @@ public static void init() { me.drex.vanish.api.VanishEvents.VANISH_EVENT.register((vanishPlayer, vanish) -> { for (ServerPlayer player : vanishPlayer.getServer().getPlayerList().getPlayers()) { if (vanish) { - if (CommonCompatibilityManager.INSTANCE.canSee(player, vanishPlayer)) { + if (CommonCompatibilityManager.INSTANCE.canSee(MinecraftCompatibilityManager.fromServerPlayer(player), MinecraftCompatibilityManager.fromServerPlayer(vanishPlayer))) { continue; } VanishEvents.ON_VANISH.invoker().accept(vanishPlayer, player); } else { - if (!CommonCompatibilityManager.INSTANCE.canSee(player, vanishPlayer)) { + if (!CommonCompatibilityManager.INSTANCE.canSee(MinecraftCompatibilityManager.fromServerPlayer(player), MinecraftCompatibilityManager.fromServerPlayer(vanishPlayer))) { continue; } VanishEvents.ON_UNVANISH.invoker().accept(vanishPlayer, player); diff --git a/fabric/src/main/java/de/maxhenkel/voicechat/intercompatibility/FabricCommonCompatibilityManager.java b/fabric/src/main/java/de/maxhenkel/voicechat/intercompatibility/FabricCommonCompatibilityManager.java index 9839445a9..ab28bd153 100644 --- a/fabric/src/main/java/de/maxhenkel/voicechat/intercompatibility/FabricCommonCompatibilityManager.java +++ b/fabric/src/main/java/de/maxhenkel/voicechat/intercompatibility/FabricCommonCompatibilityManager.java @@ -18,8 +18,8 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import java.nio.file.Path; import java.util.List; @@ -28,7 +28,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -public class FabricCommonCompatibilityManager extends CommonCompatibilityManager { +public class FabricCommonCompatibilityManager extends MinecraftCompatibilityManager { @Override public String getModVersion() { @@ -55,7 +55,7 @@ public Path getGameDirectory() { @Override public void emitServerVoiceChatConnectedEvent(ServerPlayer player) { - ServerVoiceChatEvents.VOICECHAT_CONNECTED.invoker().accept(player); + ServerVoiceChatEvents.VOICECHAT_CONNECTED.invoker().accept(getServerPlayer(player)); } @Override @@ -65,12 +65,12 @@ public void emitServerVoiceChatDisconnectedEvent(UUID clientID) { @Override public void emitPlayerCompatibilityCheckSucceeded(ServerPlayer player) { - ServerVoiceChatEvents.VOICECHAT_COMPATIBILITY_CHECK_SUCCEEDED.invoker().accept(player); + ServerVoiceChatEvents.VOICECHAT_COMPATIBILITY_CHECK_SUCCEEDED.invoker().accept(getServerPlayer(player)); } @Override public void onServerVoiceChatConnected(Consumer onVoiceChatConnected) { - ServerVoiceChatEvents.VOICECHAT_CONNECTED.register(onVoiceChatConnected); + ServerVoiceChatEvents.VOICECHAT_CONNECTED.register(serverPlayer -> onVoiceChatConnected.accept(fromServerPlayer(serverPlayer))); } @Override @@ -80,37 +80,37 @@ public void onServerVoiceChatDisconnected(Consumer onVoiceChatDisconnected @Override public void onServerStarting(Consumer onServerStarting) { - ServerLifecycleEvents.SERVER_STARTED.register(onServerStarting::accept); + ServerLifecycleEvents.SERVER_STARTED.register(minecraftServer -> onServerStarting.accept(fromServer(minecraftServer))); } @Override public void onServerStopping(Consumer onServerStopping) { - ServerLifecycleEvents.SERVER_STOPPING.register(onServerStopping::accept); + ServerLifecycleEvents.SERVER_STOPPING.register(minecraftServer -> onServerStopping.accept(fromServer(minecraftServer))); } @Override public void onPlayerLoggedIn(Consumer onPlayerLoggedIn) { - PlayerEvents.PLAYER_LOGGED_IN.register(onPlayerLoggedIn); + PlayerEvents.PLAYER_LOGGED_IN.register(serverPlayer -> onPlayerLoggedIn.accept(fromServerPlayer(serverPlayer))); } @Override public void onPlayerLoggedOut(Consumer onPlayerLoggedOut) { - PlayerEvents.PLAYER_LOGGED_OUT.register(onPlayerLoggedOut); + PlayerEvents.PLAYER_LOGGED_OUT.register(serverPlayer -> onPlayerLoggedOut.accept(fromServerPlayer(serverPlayer))); } @Override public void onPlayerHide(BiConsumer onPlayerHide) { - VanishEvents.ON_VANISH.register(onPlayerHide); + VanishEvents.ON_VANISH.register((serverPlayer, other) -> onPlayerHide.accept(fromServerPlayer(serverPlayer), fromServerPlayer(other))); } @Override public void onPlayerShow(BiConsumer onPlayerShow) { - VanishEvents.ON_UNVANISH.register(onPlayerShow); + VanishEvents.ON_UNVANISH.register((serverPlayer, other) -> onPlayerShow.accept(fromServerPlayer(serverPlayer), fromServerPlayer(other))); } @Override public void onPlayerCompatibilityCheckSucceeded(Consumer onPlayerCompatibilityCheckSucceeded) { - ServerVoiceChatEvents.VOICECHAT_COMPATIBILITY_CHECK_SUCCEEDED.register(onPlayerCompatibilityCheckSucceeded); + ServerVoiceChatEvents.VOICECHAT_COMPATIBILITY_CHECK_SUCCEEDED.register(serverPlayer -> onPlayerCompatibilityCheckSucceeded.accept(fromServerPlayer(serverPlayer))); } @Override @@ -155,7 +155,7 @@ public PermissionManager createPermissionManager() { @Override public boolean canSee(ServerPlayer player, ServerPlayer other) { - return VanishIntegration.canSee(player, other); + return VanishIntegration.canSee(getServerPlayer(player), getServerPlayer(other)); } } diff --git a/fabric/src/main/java/de/maxhenkel/voicechat/net/FabricNetManager.java b/fabric/src/main/java/de/maxhenkel/voicechat/net/FabricNetManager.java index 01cd91cb2..a34e22873 100644 --- a/fabric/src/main/java/de/maxhenkel/voicechat/net/FabricNetManager.java +++ b/fabric/src/main/java/de/maxhenkel/voicechat/net/FabricNetManager.java @@ -1,6 +1,7 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -27,17 +28,17 @@ public > Channel registerReceiver(Class packetType, bo ClientServerChannel c = new ClientServerChannel<>(); try { T dummyPacket = packetType.getDeclaredConstructor().newInstance(); - ResourceLocation identifier = dummyPacket.getIdentifier(); + ResourceLocation identifier = new ResourceLocation(dummyPacket.getIdentifier().key(), dummyPacket.getIdentifier().value()); packets.add(identifier); if (toServer) { ServerPlayNetworking.registerGlobalReceiver(identifier, (server, player, handler, buf, responseSender) -> { try { - if (!Voicechat.SERVER.isCompatible(player) && !packetType.equals(RequestSecretPacket.class)) { + if (!Voicechat.SERVER.isCompatible(player.getUUID()) && !packetType.equals(RequestSecretPacket.class)) { return; } T packet = packetType.getDeclaredConstructor().newInstance(); packet.fromBytes(buf); - c.onServerPacket(server, player, handler, packet); + c.onServerPacket(MinecraftCompatibilityManager.fromServer(server), MinecraftCompatibilityManager.fromServerPlayer(player), handler, packet); } catch (Exception e) { Voicechat.LOGGER.error("Failed to process packet", e); } diff --git a/fabric/src/main/java/de/maxhenkel/voicechat/permission/FabricPermissionManager.java b/fabric/src/main/java/de/maxhenkel/voicechat/permission/FabricPermissionManager.java index e7812354e..613ad566a 100644 --- a/fabric/src/main/java/de/maxhenkel/voicechat/permission/FabricPermissionManager.java +++ b/fabric/src/main/java/de/maxhenkel/voicechat/permission/FabricPermissionManager.java @@ -1,9 +1,10 @@ package de.maxhenkel.voicechat.permission; import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import me.lucko.fabric.api.permissions.v0.Permissions; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.ServerPlayer; public class FabricPermissionManager extends PermissionManager { @@ -14,7 +15,7 @@ public Permission createPermissionInternal(String modId, String node, Permission public boolean hasPermission(ServerPlayer player) { try { if (isFabricPermissionsAPILoaded()) { - return Permissions.check(player, modId + "." + node, type.hasPermission(player)); + return Permissions.check(MinecraftCompatibilityManager.getServerPlayer(player), modId + "." + node, type.hasPermission(player)); } } catch (Throwable t) { loaded = false; diff --git a/forge/build.gradle b/forge/build.gradle index 08a98d3d4..55dee53be 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,19 +1,32 @@ +buildscript { + println('Loading root gradle.properties') + Properties properties = new Properties() + properties.load(new FileInputStream(file('../gradle.properties'))) + properties.each { key, value -> + ext.set(key.toString(), value.toString()) + } + + Properties apiProperties = new Properties() + apiProperties.load(new FileInputStream(file('../api/gradle.properties'))) + ext.set('api_version', apiProperties.get('version')) +} + plugins { id 'net.minecraftforge.gradle' version "${forgegradle_version}" id 'org.spongepowered.mixin' version "${mixingradle_version}" + id 'com.gradleup.shadow' version "${shadow_version}" + id 'de.maxhenkel.cursegradle' version "${cursegradle_version}" + id 'com.modrinth.minotaur' version "${minotaur_version}" + id 'mod-update' version "${mod_update_version}" } -apply plugin: 'com.gradleup.shadow' -apply plugin: 'com.matthewprenger.cursegradle' -apply plugin: 'com.modrinth.minotaur' -apply plugin: 'mod-update' - apply from: "https://raw.githubusercontent.com/henkelmax/mod-gradle-scripts/${mod_gradle_script_version}/mod.gradle" +apply from: "https://raw.githubusercontent.com/henkelmax/mod-gradle-scripts/${mod_gradle_script_version}/taskutils.gradle" processResources { filesMatching('**/*.toml') { expand 'mod_version': mod_version, - 'api_version': project(':api').version, + 'api_version': api_version, 'forge_dependency': forge_dependency, 'minecraft_version': minecraft_version, 'cloth_config_version': cloth_config_version @@ -46,7 +59,7 @@ dependencies { } tasks.register('generateJava', Copy) { - from project(':common').file('src/template/java') + from file('../common/src/template/java') into "${layout.buildDirectory.asFile.get()}/generated/java" expand 'compatibility_version': voicechat_compatibility_version, 'mod_compatible_version': mod_compatible_version, @@ -57,6 +70,30 @@ sourceSets.main.java { } compileJava.dependsOn generateJava +sourceSets { + main { + java { + srcDir '../common/src/main/java' + srcDir '../common-client/src/main/java' + srcDir '../core/src/main/java' + srcDir '../api/src/main/java' + } + resources { + srcDir '../common/src/main/resources' + srcDir '../common-client/src/main/resources' + srcDir '../core/src/main/java' + srcDir '../api/src/main/resources' + } + } +} + shadowJar { relocate 'org.concentus', 'de.maxhenkel.voicechat.concentus' +} + +tasks.register('uploadMod') { + group = 'voicechat' + doLast { + runGradleTasks(['clean'], ['curseforge', 'modrinth', 'modUpdate']) + } } \ No newline at end of file diff --git a/forge/changelog.md b/forge/changelog.md index 07213e8c8..955d330c6 100644 --- a/forge/changelog.md +++ b/forge/changelog.md @@ -1 +1 @@ -- Make long text in adjust volumes screen scrollable +- Fixed volume abruptly increasing shortly after starting to speak diff --git a/forge/gradle.properties b/forge/gradle.properties index 77ea775f9..b0f9b6f80 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -1,6 +1,7 @@ -mod_loader=forge +org.gradle.jvmargs=-Xmx4G +org.gradle.daemon=false -included_projects=:api, :common, :common-client +mod_loader=forge forge_version=47.0.1 forge_dependency=[47.0.1,) diff --git a/forge/gradle/wrapper/gradle-wrapper.jar b/forge/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..1b33c55ba Binary files /dev/null and b/forge/gradle/wrapper/gradle-wrapper.jar differ diff --git a/forge/gradle/wrapper/gradle-wrapper.properties b/forge/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..d4081da47 --- /dev/null +++ b/forge/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/forge/gradlew b/forge/gradlew new file mode 100644 index 000000000..23d15a936 --- /dev/null +++ b/forge/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH="\\\"\\\"" + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/forge/gradlew.bat b/forge/gradlew.bat new file mode 100644 index 000000000..db3a6ac20 --- /dev/null +++ b/forge/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH= + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/forge/settings.gradle b/forge/settings.gradle new file mode 100644 index 000000000..1448a297e --- /dev/null +++ b/forge/settings.gradle @@ -0,0 +1,8 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { url = 'https://maven.minecraftforge.net' } + maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } + maven { url = 'https://maven.maxhenkel.de/repository/public' } + } +} \ No newline at end of file diff --git a/forge/src/main/java/de/maxhenkel/voicechat/intercompatibility/ForgeCommonCompatibilityManager.java b/forge/src/main/java/de/maxhenkel/voicechat/intercompatibility/ForgeCommonCompatibilityManager.java index ebcb1b799..6679583d7 100644 --- a/forge/src/main/java/de/maxhenkel/voicechat/intercompatibility/ForgeCommonCompatibilityManager.java +++ b/forge/src/main/java/de/maxhenkel/voicechat/intercompatibility/ForgeCommonCompatibilityManager.java @@ -12,8 +12,8 @@ import de.maxhenkel.voicechat.permission.ForgePermissionManager; import de.maxhenkel.voicechat.permission.PermissionManager; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.MinecraftServer; +import de.maxhenkel.voicechat.api.ServerPlayer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.entity.player.PlayerEvent; @@ -33,7 +33,7 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; -public class ForgeCommonCompatibilityManager extends CommonCompatibilityManager { +public class ForgeCommonCompatibilityManager extends MinecraftCompatibilityManager { private final List> serverStartingEvents; private final List> serverStoppingEvents; @@ -57,12 +57,12 @@ public ForgeCommonCompatibilityManager() { @SubscribeEvent public void serverStarting(ServerStartedEvent event) { - serverStartingEvents.forEach(consumer -> consumer.accept(event.getServer())); + serverStartingEvents.forEach(consumer -> consumer.accept(fromServer(event.getServer()))); } @SubscribeEvent public void serverStopping(ServerStoppingEvent event) { - serverStoppingEvents.forEach(consumer -> consumer.accept(event.getServer())); + serverStoppingEvents.forEach(consumer -> consumer.accept(fromServer(event.getServer()))); } @SubscribeEvent @@ -72,15 +72,15 @@ public void onRegisterCommands(RegisterCommandsEvent event) { @SubscribeEvent public void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { - if (event.getEntity() instanceof ServerPlayer player) { - playerLoggedInEvents.forEach(consumer -> consumer.accept(player)); + if (event.getEntity() instanceof net.minecraft.server.level.ServerPlayer player) { + playerLoggedInEvents.forEach(consumer -> consumer.accept(fromServerPlayer(player))); } } @SubscribeEvent public void playerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) { - if (event.getEntity() instanceof ServerPlayer player) { - playerLoggedOutEvents.forEach(consumer -> consumer.accept(player)); + if (event.getEntity() instanceof net.minecraft.server.level.ServerPlayer player) { + playerLoggedOutEvents.forEach(consumer -> consumer.accept(fromServerPlayer(player))); } } @@ -102,7 +102,7 @@ public Path getGameDirectory() { @Override public void emitServerVoiceChatConnectedEvent(ServerPlayer player) { voicechatConnectEvents.forEach(consumer -> consumer.accept(player)); - MinecraftForge.EVENT_BUS.post(new ServerVoiceChatConnectedEvent(player)); + MinecraftForge.EVENT_BUS.post(new ServerVoiceChatConnectedEvent(getServerPlayer(player))); } @Override @@ -114,7 +114,7 @@ public void emitServerVoiceChatDisconnectedEvent(UUID clientID) { @Override public void emitPlayerCompatibilityCheckSucceeded(ServerPlayer player) { voicechatCompatibilityCheckSucceededEvents.forEach(consumer -> consumer.accept(player)); - MinecraftForge.EVENT_BUS.post(new VoiceChatCompatibilityCheckSucceededEvent(player)); + MinecraftForge.EVENT_BUS.post(new VoiceChatCompatibilityCheckSucceededEvent(getServerPlayer(player))); } @Override diff --git a/forge/src/main/java/de/maxhenkel/voicechat/net/ForgeNetManager.java b/forge/src/main/java/de/maxhenkel/voicechat/net/ForgeNetManager.java index 7cb13efd8..65e7ea588 100644 --- a/forge/src/main/java/de/maxhenkel/voicechat/net/ForgeNetManager.java +++ b/forge/src/main/java/de/maxhenkel/voicechat/net/ForgeNetManager.java @@ -1,12 +1,14 @@ package de.maxhenkel.voicechat.net; import de.maxhenkel.voicechat.Voicechat; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import net.minecraft.client.Minecraft; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.network.NetworkDirection; import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.NetworkRegistry; +import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.event.EventNetworkChannel; public class ForgeNetManager extends NetManager { @@ -17,7 +19,7 @@ public > Channel registerReceiver(Class packetType, bo try { T dummyPacket = packetType.getDeclaredConstructor().newInstance(); EventNetworkChannel channel = NetworkRegistry.newEventChannel( - dummyPacket.getIdentifier(), + new ResourceLocation(dummyPacket.getIdentifier().key(), dummyPacket.getIdentifier().value()), () -> NetworkRegistry.ACCEPTVANILLA, NetworkRegistry.acceptMissingOr(NetworkRegistry.ACCEPTVANILLA), NetworkRegistry.acceptMissingOr(NetworkRegistry.ACCEPTVANILLA) @@ -29,12 +31,12 @@ public > Channel registerReceiver(Class packetType, bo NetworkEvent.Context context = event.getSource().get(); if (toServer && context.getDirection().equals(NetworkDirection.PLAY_TO_SERVER)) { try { - if (!Voicechat.SERVER.isCompatible(context.getSender()) && !packetType.equals(RequestSecretPacket.class)) { + if (!Voicechat.SERVER.isCompatible(MinecraftCompatibilityManager.fromServerPlayer(context.getSender())) && !packetType.equals(RequestSecretPacket.class)) { return; } T packet = packetType.getDeclaredConstructor().newInstance(); packet.fromBytes(event.getPayload()); - c.onServerPacket(context.getSender().server, context.getSender(), context.getSender().connection, packet); + c.onServerPacket(MinecraftCompatibilityManager.fromServer(context.getSender().server), MinecraftCompatibilityManager.fromServerPlayer(context.getSender()), context.getSender().connection, packet); context.setPacketHandled(true); } catch (Exception e) { Voicechat.LOGGER.error("Failed to process packet", e); diff --git a/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermission.java b/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermission.java index 9fc0fafb3..49ff18878 100644 --- a/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermission.java +++ b/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermission.java @@ -1,6 +1,7 @@ package de.maxhenkel.voicechat.permission; -import net.minecraft.server.level.ServerPlayer; +import de.maxhenkel.voicechat.api.ServerPlayer; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import net.minecraftforge.server.permission.PermissionAPI; import net.minecraftforge.server.permission.nodes.PermissionNode; @@ -16,7 +17,7 @@ public ForgePermission(PermissionNode node, PermissionType type) { @Override public boolean hasPermission(ServerPlayer player) { - return PermissionAPI.getPermission(player, node); + return PermissionAPI.getPermission(MinecraftCompatibilityManager.getServerPlayer(player), node); } @Override diff --git a/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermissionManager.java b/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermissionManager.java index aa1d30889..190a34453 100644 --- a/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermissionManager.java +++ b/forge/src/main/java/de/maxhenkel/voicechat/permission/ForgePermissionManager.java @@ -1,5 +1,6 @@ package de.maxhenkel.voicechat.permission; +import de.maxhenkel.voicechat.intercompatibility.MinecraftCompatibilityManager; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.server.permission.events.PermissionGatherEvent; import net.minecraftforge.server.permission.nodes.PermissionNode; @@ -11,7 +12,7 @@ public class ForgePermissionManager extends PermissionManager { @Override public Permission createPermissionInternal(String modId, String node, PermissionType type) { - return new ForgePermission(new PermissionNode<>(modId, node, PermissionTypes.BOOLEAN, (player, playerUUID, context) -> type.hasPermission(player)), type); + return new ForgePermission(new PermissionNode<>(modId, node, PermissionTypes.BOOLEAN, (player, playerUUID, context) -> type.hasPermission(MinecraftCompatibilityManager.fromServerPlayer(player))), type); } @SubscribeEvent diff --git a/gradle.properties b/gradle.properties index 0bf5c6367..7c499d058 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ lame4j_version=2.1.5 speex4j_version=1.0.3 # Mod information -mod_version=1.20.1-2.6.7 +mod_version=1.20.1-2.6.10 mod_compatible_version=2.6.x mod_id=voicechat mod_display_name=Simple Voice Chat @@ -37,14 +37,13 @@ upload_release_type=release upload_recommended=true # Gradle plugins -mod_gradle_script_version=1.0.44 -fabric_loom_version=1.13-SNAPSHOT -quilt_loom_version=1.8.+ +mod_gradle_script_version=1.0.58 +fabric_loom_version=1.14-SNAPSHOT +quilt_loom_version=1.11.+ forgegradle_version=[6.0.16,6.2) mod_update_version=2.0.0 -cursegradle_version=1.4.0 -shadow_version=8.3.6 +cursegradle_version=1.5.1 +shadow_version=9.2.2 minotaur_version=2.+ mixingradle_version=0.7-SNAPSHOT -curse_gradle_uploader_version=1.5.1 maven_settings_version=0.5 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 1b33c55ba..f8e1ee312 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d4081da47..23449a2b5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 23d15a936..adff685a0 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" diff --git a/gradlew.bat b/gradlew.bat index db3a6ac20..c4bdd3ab8 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/quilt/build.gradle b/quilt/build.gradle index f6ebb558b..64f516321 100644 --- a/quilt/build.gradle +++ b/quilt/build.gradle @@ -14,7 +14,7 @@ buildscript { plugins { id 'org.quiltmc.loom' version "${quilt_loom_version}" id 'com.gradleup.shadow' version "${shadow_version}" - id 'com.matthewprenger.cursegradle' version "${cursegradle_version}" + id 'de.maxhenkel.cursegradle' version "${cursegradle_version}" id 'com.modrinth.minotaur' version "${minotaur_version}" id 'mod-update' version "${mod_update_version}" } diff --git a/quilt/changelog.md b/quilt/changelog.md index 07213e8c8..955d330c6 100644 --- a/quilt/changelog.md +++ b/quilt/changelog.md @@ -1 +1 @@ -- Make long text in adjust volumes screen scrollable +- Fixed volume abruptly increasing shortly after starting to speak diff --git a/quilt/gradle/wrapper/gradle-wrapper.jar b/quilt/gradle/wrapper/gradle-wrapper.jar index a4b76b953..1b33c55ba 100644 Binary files a/quilt/gradle/wrapper/gradle-wrapper.jar and b/quilt/gradle/wrapper/gradle-wrapper.jar differ diff --git a/quilt/gradle/wrapper/gradle-wrapper.properties b/quilt/gradle/wrapper/gradle-wrapper.properties index df97d72b8..d4081da47 100644 --- a/quilt/gradle/wrapper/gradle-wrapper.properties +++ b/quilt/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/quilt/gradlew b/quilt/gradlew index f5feea6d6..23d15a936 100644 --- a/quilt/gradlew +++ b/quilt/gradlew @@ -86,8 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -115,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -206,7 +205,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. @@ -214,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/quilt/gradlew.bat b/quilt/gradlew.bat index 9d21a2183..db3a6ac20 100644 --- a/quilt/gradlew.bat +++ b/quilt/gradlew.bat @@ -70,11 +70,11 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index 18ca0447d..13ade94d2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,10 +4,8 @@ pluginManagement { maven { url = 'https://maven.fabricmc.net/' } maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } maven { url = 'https://maven.maxhenkel.de/repository/public' } - maven { url = 'https://maven.minecraftforge.net' } - maven { url = 'https://repo.u-team.info' } } } rootProject.name = 'voicechat' -include('api', 'common', 'common-client', 'fabric', 'fabric:api-stub', 'forge') \ No newline at end of file +include('api', 'core', 'common', 'common-client', 'fabric', 'fabric:api-stub') \ No newline at end of file