From f95e4f82adb130c9279a0ffd5189a7322cabc4b0 Mon Sep 17 00:00:00 2001 From: SamB440 Date: Mon, 4 Dec 2023 12:49:42 +0000 Subject: [PATCH] Allow playing custom sounds on discovery --- api/build.gradle.kts | 6 ++-- .../data/region/ConfiguredRegion.java | 10 +++---- rpgregions/build.gradle.kts | 4 ++- .../rpgregions/listener/RegionListener.java | 21 +++++++------- .../managers/RPGRegionsManagers.java | 28 +++++++++++-------- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 731d735..f3095d0 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,5 +1,3 @@ -import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.exclude - plugins { id("maven-publish") } @@ -22,14 +20,16 @@ dependencies { compileOnly("com.sk89q.worldguard:worldguard-bukkit:${properties["worldguard_version"]}") { exclude("com.destroystokyo.paper") exclude("org.spigotmc") + exclude("com.google") } compileOnly("com.sk89q.worldedit:worldedit-bukkit:${properties["worldedit_version"]}") { exclude("com.google") exclude("org.bukkit") exclude("org.spigotmc") } - compileOnly("io.lumine:Mythic-Dist:5.2.1") { + compileOnly("io.lumine:Mythic-Dist:5.3.5") { exclude("org.apache.commons") + exclude("com.google") } } diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java index affcfa0..b5bf1eb 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java @@ -46,7 +46,7 @@ public class ConfiguredRegion { private String id; private String customName; private final List rewards; - @NeedsGUI private Sound sound; + @NeedsGUI private String soundName; private String icon; private int iconModel; private int undiscoveredIconModel; @@ -89,7 +89,7 @@ public class ConfiguredRegion { this.id = id; this.customName = customName; this.rewards = rewards; - this.sound = Sound.UI_TOAST_CHALLENGE_COMPLETE; + this.soundName = Sound.UI_TOAST_CHALLENGE_COMPLETE.name(); Optional defaultIcon = Optional.of(Material.valueOf(RPGRegionsAPI.getAPI().getConfig().getString("settings.server.gui.default_region_icon"))); this.icon = defaultIcon.map(Enum::name).orElseGet(Material.TOTEM_OF_UNDYING::name); this.undiscoveredIcon = defaultIcon.map(Enum::name).orElseGet(Material.TOTEM_OF_UNDYING::name); @@ -116,7 +116,7 @@ public class ConfiguredRegion { public ConfiguredRegion(@Nullable World world, String id, String customName, List rewards, List effects, Sound sound, Material icon) { this(world, id, customName, rewards, effects); - this.sound = sound; + this.soundName = sound.name(); this.icon = icon.name(); } @@ -142,8 +142,8 @@ public class ConfiguredRegion { } @Nullable - public Sound getSound() { - return sound; + public String getSoundName() { + return soundName; } @Nullable diff --git a/rpgregions/build.gradle.kts b/rpgregions/build.gradle.kts index a7732a3..fde3b5c 100644 --- a/rpgregions/build.gradle.kts +++ b/rpgregions/build.gradle.kts @@ -35,6 +35,7 @@ dependencies { compileOnly("com.sk89q.worldguard:worldguard-bukkit:${properties["worldguard_version"]}") { exclude("com.destroystokyo.paper") exclude("org.spigotmc") + exclude("com.google") } compileOnly("com.sk89q.worldedit:worldedit-bukkit:${properties["worldedit_version"]}") { exclude("com.google") @@ -58,8 +59,9 @@ dependencies { compileOnly("net.Indyuce:MMOCore-API:1.11.0-SNAPSHOT") compileOnly("com.github.shynixn.headdatabase:hdb-api:1.0") // head database compileOnly("com.github.plan-player-analytics:Plan:5.5.2307") // plan - compileOnly("io.lumine:Mythic-Dist:5.2.1") { + compileOnly("io.lumine:Mythic-Dist:5.3.5") { exclude("org.apache.commons") + exclude("com.google") } compileOnly(":Dynmap-3.5-beta-3-spigot") // Dynmap compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT") { diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/listener/RegionListener.java b/rpgregions/src/main/java/net/islandearth/rpgregions/listener/RegionListener.java index cc5869a..dae7b11 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/listener/RegionListener.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/listener/RegionListener.java @@ -1,5 +1,6 @@ package net.islandearth.rpgregions.listener; +import com.google.common.base.Enums; import net.islandearth.rpgregions.RPGRegions; import net.islandearth.rpgregions.api.events.RegionDiscoverEvent; import net.islandearth.rpgregions.api.events.RegionsEnterEvent; @@ -130,21 +131,21 @@ public class RegionListener implements Listener { ConfiguredRegion region = rde.getRegion(); this.sendTitles(player, region, true); - if (region.getSound() == null) { + final String soundName = region.getSoundName(); + final String configSound = soundName != null ? soundName : plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name", ""); + Enums.getIfPresent(Sound.class, configSound).toJavaUtil().ifPresentOrElse(sound -> { player.playSound( player.getLocation(), - Sound.valueOf(plugin.getConfig().getString("settings.server.discoveries.discovered.sound.name")), + sound, 1, plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch") ); - } else { - player.playSound( - player.getLocation(), - region.getSound(), - 1, - plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch") - ); - } + }, () -> player.playSound( + player.getLocation(), + configSound, + 1, + plugin.getConfig().getInt("settings.server.discoveries.discovered.sound.pitch") + )); if (region.getRewards() != null) region.getRewards().forEach(reward -> reward.award(player)); diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/managers/RPGRegionsManagers.java b/rpgregions/src/main/java/net/islandearth/rpgregions/managers/RPGRegionsManagers.java index 04d1070..f0fea45 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/managers/RPGRegionsManagers.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/managers/RPGRegionsManagers.java @@ -50,6 +50,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -69,7 +70,6 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; -import java.util.stream.Collectors; import java.util.stream.Stream; public class RPGRegionsManagers implements IRPGRegionsManagers { @@ -122,21 +122,13 @@ public class RPGRegionsManagers implements IRPGRegionsManagers { true, Collections.singletonList(new ItemStackBuilder(Material.IRON_CHESTPLATE).build()))); - ConfiguredRegion configuredRegion = new ConfiguredRegion(null, "exampleconfig", "ExampleConfig", rewards, effects, - Sound.AMBIENT_UNDERWATER_EXIT, - Material.WOODEN_AXE); - configuredRegion.setRegenerate(new Regenerate(50000, - false, - Collections.singletonList( - new RegeneratingEntity(EntityType.SHULKER, Arrays.asList( - Material.PURPUR_BLOCK, - Material.PURPUR_PILLAR), 5, 30)))); + final ConfiguredRegion configuredRegion = createExampleRegion(rewards, effects); configuredRegion.getIconCommand().add(new IconCommand("say", IconCommand.CommandClickType.DISCOVERED, 0)); configuredRegion.save(plugin); Stream files = Files.walk(Paths.get(folder.getPath())); files.filter(Files::isRegularFile) - .collect(Collectors.toList()) + .toList() .forEach(path -> { File file = path.toFile(); plugin.debug("Walking file tree: " + file); @@ -188,6 +180,20 @@ public class RPGRegionsManagers implements IRPGRegionsManagers { } } + @NotNull + private static ConfiguredRegion createExampleRegion(List rewards, List effects) { + ConfiguredRegion configuredRegion = new ConfiguredRegion(null, "exampleconfig", "ExampleConfig", rewards, effects, + Sound.AMBIENT_UNDERWATER_EXIT, + Material.WOODEN_AXE); + configuredRegion.setRegenerate(new Regenerate(50000, + false, + Collections.singletonList( + new RegeneratingEntity(EntityType.SHULKER, Arrays.asList( + Material.PURPUR_BLOCK, + Material.PURPUR_PILLAR), 5, 30)))); + return configuredRegion; + } + private void warnBlocking(RPGRegions plugin, ConfiguredRegion region) { List blocking = new ArrayList<>(); for (DiscoveryReward reward : region.getRewards()) {