From d13759afccf0c18a23ca22c523b8065668076f29 Mon Sep 17 00:00:00 2001 From: Mats - ToetMats Date: Sat, 1 Feb 2025 22:05:18 +0100 Subject: [PATCH] Add the requested API and config features (#469) * Add the requested API and config features * some more fixes --- .tool-versions | 2 +- .../craftmend/openaudiomc/api/VoiceApi.java | 24 +++++++++++ dev-resources/spawn-test-spigot.sh | 2 +- .../mapdb-migrator/dependency-reduced-pom.xml | 2 +- .../parties-module/dependency-reduced-pom.xml | 2 +- .../skywars-module/dependency-reduced-pom.xml | 2 +- .../vistas-client/dependency-reduced-pom.xml | 2 +- .../dependency-reduced-pom.xml | 2 +- .../static-resources/project_status.json | 2 +- plugin/src/main/bash/data.bin | 2 +- .../api/implementaions/VoiceApiImpl.java | 24 +++++++++++ .../client/objects/ClientConnection.java | 8 ++-- .../generic/migrations/MigrationWorker.java | 1 + .../generic/storage/enums/StorageKey.java | 3 ++ .../tasks/SpeakerGarbageCollection.java | 2 +- .../modules/speakers/utils/SpeakerUtils.java | 40 ++++++++++--------- .../modules/traincarts/models/TrainMedia.java | 4 ++ .../spigot/services/threading/Executor.java | 1 - .../velocity/OpenAudioMcVelocity.java | 2 +- plugin/src/main/resources/bungee.yml | 2 +- plugin/src/main/resources/config.yml | 6 +++ plugin/src/main/resources/data.bin | 2 +- .../resources/openaudiomc-build.properties | 4 +- plugin/src/main/resources/plugin.yml | 2 +- pom.xml | 2 +- 25 files changed, 105 insertions(+), 40 deletions(-) diff --git a/.tool-versions b/.tool-versions index b1e51edda4..bb5e993457 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -java adoptopenjdk-8.0.332+9 +java openjdk-21 diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java b/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java index b58c666ce9..926886e23c 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/VoiceApi.java @@ -162,5 +162,29 @@ static VoiceApi getInstance() { */ boolean isChannelNameValid(String s); + /** + * Check if a client has voicechat moderation enabled + * @param client the client to check + * @return true if the client has moderation enabled + * @since 6.10.9 + */ + boolean isClientModerating(Client client); + + /** + * Start a moderation session for a client, bypassing permission checks. + * Moderation will still have to be enabled in the config, otherwise this method will return false and do nothing. + * Moderation mode isn't permanent, it will only last for the duration you have configured in the config, but you can call this method again to extend the duration. + * @param client the client to enable or disable moderation for + * @return true if the client is now moderating + * @since 6.10.9 + */ + boolean startClientModeration(Client client); + + /** + * Stop a moderation session for a client + * @param client the client to stop moderation for + * @since 6.10.9 + */ + void stopClientModeration(Client client); } diff --git a/dev-resources/spawn-test-spigot.sh b/dev-resources/spawn-test-spigot.sh index 30f9239979..16c692c7fb 100755 --- a/dev-resources/spawn-test-spigot.sh +++ b/dev-resources/spawn-test-spigot.sh @@ -28,4 +28,4 @@ echo "Starting server.." rm world/session.lock rm world_the_end/session.lock rm world_nether/session.lock -java -Xms3G -Xmx3G -DIReallyKnowWhatIAmDoingISwear -jar spigot-1.21.4.jar nogui +java -Xms3G -Xmx3G -DIReallyKnowWhatIAmDoingISwear -jar paper-1.20.4-499.jar nogui diff --git a/modules/mapdb-migrator/dependency-reduced-pom.xml b/modules/mapdb-migrator/dependency-reduced-pom.xml index c3629f80b4..87c03ce7df 100644 --- a/modules/mapdb-migrator/dependency-reduced-pom.xml +++ b/modules/mapdb-migrator/dependency-reduced-pom.xml @@ -107,7 +107,7 @@ com.craftmend.openaudiomc openaudiomc - 6.10.8 + 6.10.9 provided diff --git a/modules/parties-module/dependency-reduced-pom.xml b/modules/parties-module/dependency-reduced-pom.xml index c93f76d0eb..4d1f1d09d3 100644 --- a/modules/parties-module/dependency-reduced-pom.xml +++ b/modules/parties-module/dependency-reduced-pom.xml @@ -112,7 +112,7 @@ com.craftmend.openaudiomc openaudiomc - 6.10.8 + 6.10.9 provided diff --git a/modules/skywars-module/dependency-reduced-pom.xml b/modules/skywars-module/dependency-reduced-pom.xml index 51f23d7f59..ecccc292bb 100644 --- a/modules/skywars-module/dependency-reduced-pom.xml +++ b/modules/skywars-module/dependency-reduced-pom.xml @@ -112,7 +112,7 @@ com.craftmend.openaudiomc openaudiomc - 6.10.8 + 6.10.9 provided diff --git a/modules/vistas-client/dependency-reduced-pom.xml b/modules/vistas-client/dependency-reduced-pom.xml index 8bf37052a1..2e40c77abd 100644 --- a/modules/vistas-client/dependency-reduced-pom.xml +++ b/modules/vistas-client/dependency-reduced-pom.xml @@ -115,7 +115,7 @@ com.craftmend.openaudiomc openaudiomc - 6.10.8 + 6.10.9 provided diff --git a/modules/voice-join-permission/dependency-reduced-pom.xml b/modules/voice-join-permission/dependency-reduced-pom.xml index 278e2d3b37..4eef439cac 100644 --- a/modules/voice-join-permission/dependency-reduced-pom.xml +++ b/modules/voice-join-permission/dependency-reduced-pom.xml @@ -108,7 +108,7 @@ com.craftmend.openaudiomc openaudiomc - 6.10.8 + 6.10.9 provided diff --git a/plugin/protocol/static-resources/project_status.json b/plugin/protocol/static-resources/project_status.json index 1b3f44ce59..3196d12a8a 100644 --- a/plugin/protocol/static-resources/project_status.json +++ b/plugin/protocol/static-resources/project_status.json @@ -1,7 +1,7 @@ { "response": { "versioning": { - "version_tag": "6.10.7", + "version_tag": "6.10.9", "build_number": 700, "version_importance": "&e&aHighly Recommended", "version_update_message": "Migrated to a new platform, free CDN, settings, routing, and much more! Please read the changelog for more information and a guide on how to migrate." diff --git a/plugin/src/main/bash/data.bin b/plugin/src/main/bash/data.bin index 69e5624876..0030837419 100755 --- a/plugin/src/main/bash/data.bin +++ b/plugin/src/main/bash/data.bin @@ -1 +1 @@ -BUILD_NUM="1521" +BUILD_NUM="1531" diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java index 75c2cc3b15..0b83b3f77a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/implementaions/VoiceApiImpl.java @@ -16,6 +16,7 @@ import com.craftmend.openaudiomc.generic.networking.packets.client.voice.PacketClientVoiceOptionsUpdate; import com.craftmend.openaudiomc.generic.networking.payloads.client.voice.ClientVoiceOptionsPayload; import com.craftmend.openaudiomc.generic.platform.Platform; +import com.craftmend.openaudiomc.generic.storage.enums.StorageKey; import com.craftmend.openaudiomc.spigot.modules.voicechat.VoiceChannelService; import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.FilterService; import org.jetbrains.annotations.Nullable; @@ -183,4 +184,27 @@ public void deleteChannel(VoiceChannel channel) { public boolean isChannelNameValid(String s) { return OpenAudioMc.getService(VoiceChannelService.class).isChannelNameValid(s); } + + @Override + public boolean isClientModerating(Client client) { + ClientConnection clientConnection = (ClientConnection) client; + return clientConnection.getSession().isModerating(); + } + + @Override + public boolean startClientModeration(Client client) { + ClientConnection clientConnection = (ClientConnection) client; + if (!StorageKey.SETTINGS_VC_MOD_ENABLED.getBoolean()) { + return false; + } + + clientConnection.setModerating(true); + return true; + } + + @Override + public void stopClientModeration(Client client) { + ClientConnection clientConnection = (ClientConnection) client; + clientConnection.setModerating(false); + } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java index b19c9a749b..03179e60ec 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java @@ -197,10 +197,12 @@ public void kick(Runnable callback) { */ public void setModerating(boolean state) { if (state) { - session.setModerating(true); session.setModerationTimeRemaining(OpenAudioMc.getInstance().getConfiguration().getInt(StorageKey.SETTINGS_MODERATION_TIMER)); - session.setResetVc(true); - sendPacket(new PacketClientModerationStatus(true)); + if (!session.isModerating()) { + session.setResetVc(true); + sendPacket(new PacketClientModerationStatus(true)); + } + session.setModerating(true); } else { session.setModerating(false); session.setModerationTimeRemaining(0); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java index d8699a9a1a..7dc46d2b5a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java @@ -64,6 +64,7 @@ public void handleMigrations() { new AddConfigKeyMigration(SETTINGS_SPEAKER_MAX_RANGE, "Add max range config value"), new AddConfigKeyMigration(SETTINGS_STATIC_CHANNELS_SHOW_IN_WEB_UI, "Add a setting to show the channels web UI"), new AddConfigKeyMigration(SETTINGS_SPEAKER_SKIN_UUID, "Add a setting for the speaker skin textures"), + new AddConfigKeyMigration(SETTINGS_TRAINCARTS_MUTE_REGIONS, "Add a setting to mute regions and speakers in traincarts"), }; for (SimpleMigration migration : migrations) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java index 13e6c0a615..9dcbe91d10 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java @@ -107,6 +107,9 @@ public enum StorageKey { SETTINGS_IGNORE_REGIONS_WHILE_IN_VEHICLE(false, "options.ignore-regions-on-vehicles", StorageLocation.CONFIG_FILE), SETTINGS_HYDRATE_REGIONS_ON_BOOT(false, "options.hydrate-regions-on-boot", StorageLocation.CONFIG_FILE), + SETTINGS_TRAINCARTS_MUTE_REGIONS(false, "options.traincarts-mute-regions", StorageLocation.CONFIG_FILE), + SETTINGS_TRAINCARTS_MUTE_SPEAKERS(false, "options.traincarts-mute-speakers", StorageLocation.CONFIG_FILE), + SETTINGS_STATIC_CHANNELS_ENABLED(false, "static-channels.enabled", StorageLocation.CONFIG_FILE), SETTINGS_STATIC_CHANNELS_SHOW_IN_WEB_UI(false, "static-channels.show-in-webclient", StorageLocation.CONFIG_FILE), SETTINGS_STATIC_CHANNELS_BASE(false, "static-channels.list", StorageLocation.CONFIG_FILE), diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java index 08c0dbde3b..72e0e83b10 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java @@ -57,7 +57,7 @@ public void run() { possiblyFilterLimits(setSize, this.speakerService .getSpeakerMap() .values().stream() - .filter(Speaker::getRequiresHealthCheck) + .filter(speaker -> speaker != null && speaker.getRequiresHealthCheck()) .filter(speaker -> !speaker.getValidated()) .skip(fractionStart) ).collect(Collectors.toList()) diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java index ea487a6b59..f768ce1041 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java @@ -12,6 +12,7 @@ import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.block.Skull; import org.bukkit.inventory.ItemStack; @@ -28,6 +29,10 @@ public class SpeakerUtils { public static final String speakerSkin = SETTINGS_SPEAKER_SKIN_NAME.getString(); public static final UUID speakerUUID = UUID.fromString(SETTINGS_SPEAKER_SKIN_UUID.getString()); public static final String textureValue; + private static OfflinePlayer FAKE_SKULL_OWNER = new ClassMocker(OfflinePlayer.class) + .addReturnValue("getUniqueId", speakerUUID) + .addReturnValue("getName", speakerSkin) + .createProxy(); static { String rawUrl = SETTINGS_SPEAKER_SKIN_TEXTURE.getString(); @@ -56,7 +61,6 @@ public static boolean isSpeakerSkull(Block block) { } return valid; } - return skull.getOwningPlayer().getUniqueId().equals(speakerUUID); } else { if (skull.getOwner() == null) return false; @@ -70,13 +74,25 @@ public static ItemStack getSkull(String source, int radius) { ItemStack skull = new ItemStack(SPEAKER_SERVICE.getPlayerSkullItem()); skull.setDurability((short) 3); + SkullMeta sm = (SkullMeta) skull.getItemMeta(); + if (sm != null) { + sm.setDisplayName(ChatColor.AQUA + "OpenAudioMc Speaker"); + sm.setOwningPlayer(FAKE_SKULL_OWNER); + sm.setLore(Arrays.asList( + ChatColor.AQUA + "I'm a super cool speaker!", + ChatColor.AQUA + "Simply place me in your world", + ChatColor.AQUA + "and I'll play your customized music", + "", + ChatColor.AQUA + "SRC: " + ChatColor.GREEN + source, + ChatColor.AQUA + "Radius: " + ChatColor.GREEN + radius + )); + skull.setItemMeta(sm); + } + // For Minecraft 1.20.4 and below NBT.modify(skull, nbt -> { ReadWriteNBT skullOwnerCompound = nbt.getOrCreateCompound("SkullOwner"); - - // The owner UUID. Note that skulls with the same UUID but different textures will misbehave and only one texture will load. - // They will share the texture. To avoid this limitation, it is recommended to use a random UUID. - skullOwnerCompound.setUUID("Id", UUID.randomUUID()); + skullOwnerCompound.setUUID("Id", speakerUUID); skullOwnerCompound.getOrCreateCompound("Properties") .getCompoundList("textures") @@ -100,20 +116,6 @@ public static ItemStack getSkull(String source, int radius) { } } - SkullMeta sm = (SkullMeta) skull.getItemMeta(); - if (sm != null) { - sm.setDisplayName(ChatColor.AQUA + "OpenAudioMc Speaker"); - sm.setLore(Arrays.asList( - ChatColor.AQUA + "I'm a super cool speaker!", - ChatColor.AQUA + "Simply place me in your world", - ChatColor.AQUA + "and I'll play your customized music", - "", - ChatColor.AQUA + "SRC: " + ChatColor.GREEN + source, - ChatColor.AQUA + "Radius: " + ChatColor.GREEN + radius - )); - skull.setItemMeta(sm); - } - NBTItem nbti = new NBTItem(skull); nbti.setString("oa-src", source); nbti.setInteger("oa-radius", radius); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/traincarts/models/TrainMedia.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/traincarts/models/TrainMedia.java index eae7b54503..8c741b5685 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/traincarts/models/TrainMedia.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/traincarts/models/TrainMedia.java @@ -3,6 +3,7 @@ import com.craftmend.openaudiomc.OpenAudioMc; import com.craftmend.openaudiomc.api.media.Media; import com.craftmend.openaudiomc.generic.media.time.TimeService; +import com.craftmend.openaudiomc.generic.storage.enums.StorageKey; import lombok.Data; import java.time.Instant; @@ -20,6 +21,9 @@ public TrainMedia(String source) { this.media.setDoPickup(true); this.media.setMediaId("train_audio"); this.media.setLoop(false); + + this.media.setMuteRegions(StorageKey.SETTINGS_TRAINCARTS_MUTE_REGIONS.getBoolean()); + this.media.setMuteSpeakers(StorageKey.SETTINGS_TRAINCARTS_MUTE_SPEAKERS.getBoolean()); } public Media toMedia() { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java index 037272f60c..493b627014 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java @@ -91,7 +91,6 @@ public void setPauseRuns(int pauseRuns) { public void stop() { running = false; - this.thread.stop(); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java index b11c7033df..754fb52615 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java @@ -37,7 +37,7 @@ @Plugin( id = "openaudiomc", name = "OpenAudioMc Bungee Plugin Port for Velocity", - version = "6.10.8", + version = "6.10.9", authors = {"Mindgamesnl", "fluse1367"}, description = "OpenAudioMc: Proximity voice chat & audio plugin for Minecraft, no mods needed. Supports Bungeecord, Velocity, Spigot & more.", url = "https://openaudiomc.net/" diff --git a/plugin/src/main/resources/bungee.yml b/plugin/src/main/resources/bungee.yml index 1336291c1b..2dac186bb1 100644 --- a/plugin/src/main/resources/bungee.yml +++ b/plugin/src/main/resources/bungee.yml @@ -1,5 +1,5 @@ name: OpenAudioMc -version: 6.10.7 +version: 6.10.9 main: com.craftmend.openaudiomc.bungee.OpenAudioMcBungee author: Mindgamesnl authors: [Mindgamesnl] diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index dd0a984a13..d6bddd8dfb 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -293,6 +293,12 @@ options: # This is useful for when you have a bad connection, but it can be disabled if its causing issues. auto-reconnect: true + # This setting determines if the media played in a train should overwrite any media from regions + traincarts-mute-regions: false + + # This setting determines if the media played in a train should overwrite any media from speakers + traincarts-mute-speakers: false + # Voicechat filters define requirements that players both have to meet before they will be able to hear eachother. # You can implement custom filters through the API, or enable some of the default ones below. vc-filter: diff --git a/plugin/src/main/resources/data.bin b/plugin/src/main/resources/data.bin index 69e5624876..0030837419 100755 --- a/plugin/src/main/resources/data.bin +++ b/plugin/src/main/resources/data.bin @@ -1 +1 @@ -BUILD_NUM="1521" +BUILD_NUM="1531" diff --git a/plugin/src/main/resources/openaudiomc-build.properties b/plugin/src/main/resources/openaudiomc-build.properties index 19d8600338..109fb05ad0 100644 --- a/plugin/src/main/resources/openaudiomc-build.properties +++ b/plugin/src/main/resources/openaudiomc-build.properties @@ -1,3 +1,3 @@ -BUILD_VERSION="1521" -BUILD_COMMIT="91938ed8d427753d44da69a41757873cbd5451cf" +BUILD_VERSION="1531" +BUILD_COMMIT="f096ea69ea9b8334f56c8eae16b41d0efba888a4" BUILD_AUTHOR="Mats" diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index f60cce1987..4319094862 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: OpenAudioMc -version: 6.10.7 +version: 6.10.9 softdepend: [WorldGuard, Train_Carts, LiteBans, Essentials, PlaceholderAPI] main: com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot api-version: 1.13 diff --git a/pom.xml b/pom.xml index 52552be05c..2dee763691 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ The OpenAudioMc Java plugin and Api UTF-8 - 6.10.8 + 6.10.9 1.18.36