9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2026-01-04 15:31:38 +00:00

Allow playing custom sounds on discovery

This commit is contained in:
SamB440
2023-12-04 12:49:42 +00:00
parent 66f8ff897d
commit f95e4f82ad
5 changed files with 39 additions and 30 deletions

View File

@@ -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")
}
}

View File

@@ -46,7 +46,7 @@ public class ConfiguredRegion {
private String id;
private String customName;
private final List<DiscoveryReward> 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<Material> 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<DiscoveryReward> rewards, List<RegionEffect> 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

View File

@@ -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") {

View File

@@ -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));

View File

@@ -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<Path> 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<DiscoveryReward> rewards, List<RegionEffect> 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> blocking = new ArrayList<>();
for (DiscoveryReward reward : region.getRewards()) {