diff --git a/src/main/java/com/volmit/adapt/api/Component.java b/src/main/java/com/volmit/adapt/api/Component.java index bef66951..35b52f92 100644 --- a/src/main/java/com/volmit/adapt/api/Component.java +++ b/src/main/java/com/volmit/adapt/api/Component.java @@ -27,6 +27,7 @@ import com.volmit.adapt.api.value.MaterialValue; import com.volmit.adapt.api.xp.XP; import com.volmit.adapt.util.J; +import com.volmit.adapt.util.SoundPlayer; import com.volmit.adapt.util.reflect.enums.PotionTypes; import org.bukkit.*; import org.bukkit.block.Block; @@ -213,7 +214,7 @@ default boolean isAdaptableDamageCause(EntityDamageEvent event) { default void addPotionStacks(Player p, PotionEffectType potionEffect, int amplifier, int duration, boolean overlap) { List activeEffects = new ArrayList<>(p.getActivePotionEffects()); - + SoundPlayer sp = SoundPlayer.of(p); for (PotionEffect activeEffect : activeEffects) { if (activeEffect.getType() == potionEffect) { if (!overlap) { @@ -224,7 +225,7 @@ default void addPotionStacks(Player p, PotionEffectType potionEffect, int amplif int newAmplifier = Math.max(activeEffect.getAmplifier(), amplifier); p.removePotionEffect(potionEffect); p.addPotionEffect(new PotionEffect(potionEffect, newDuration, newAmplifier)); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f); return; } } @@ -237,7 +238,7 @@ default void addPotionStacks(Player p, PotionEffectType potionEffect, int amplif } J.s(() -> { p.addPotionEffect(new PotionEffect(potionEffect, duration, amplifier)); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f); }); }); @@ -805,7 +806,8 @@ default void damageHand(Player p, int damage) { if (dm.getDamage() > is.getType().getMaxDurability()) { p.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1f, 1f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1f, 1f); return; } @@ -830,7 +832,8 @@ default void damageOffHand(Player p, int damage) { if (dm.getDamage() > is.getType().getMaxDurability()) { p.getInventory().setItemInOffHand(new ItemStack(Material.AIR)); - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1f, 1f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1f, 1f); return; } diff --git a/src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java b/src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java index a4cea506..ccdc7e3b 100644 --- a/src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java +++ b/src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java @@ -389,9 +389,10 @@ default void openGui(Player player) { return; } - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 0.655f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 0.855f); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 0.655f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 0.855f); Window w = new UIWindow(player); w.setTag("skill/" + getSkill().getName() + "/" + getName()); w.setDecorator((window, position, row) -> new UIElement("bg").setName(" ").setMaterial(new MaterialBlock(Material.BLACK_STAINED_GLASS_PANE))); @@ -437,13 +438,12 @@ default void openGui(Player player) { .onLeftClick((e) -> { if (mylevel >= lvl) { unlearn(player, lvl, false); - - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_NETHER_GOLD_ORE_PLACE, 0.7f, 1.355f); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.4f, 0.755f); + spw.play(player.getLocation(), Sound.BLOCK_NETHER_GOLD_ORE_PLACE, 0.7f, 1.355f); + spw.play(player.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.4f, 0.755f); w.close(); if (AdaptConfig.get().getLearnUnlearnButtonDelayTicks() != 0) { if (isPermanent()) { - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 0.5f, 1.355f); + spw.play(player.getLocation(), Sound.ENTITY_BLAZE_DEATH, 0.5f, 1.355f); player.sendTitle(" ", C.RED + "" + C.BOLD + Localizer.dLocalize("snippets", "adaptmenu", "maynotunlearn") + " " + getDisplayName(mylevel), 1, 10, 11); } else { player.sendTitle(" ", C.GRAY + Localizer.dLocalize("snippets", "adaptmenu", "unlearned") + " " + getDisplayName(mylevel), 1, 10, 11); @@ -456,13 +456,13 @@ default void openGui(Player player) { if (k >= c && getPlayer(player).getData().hasPowerAvailable(pc)) { if (getPlayer(player).getData().getSkillLine(getSkill().getName()).spendKnowledge(c)) { getPlayer(player).getData().getSkillLine(getSkill().getName()).setAdaptation(this, lvl); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_NETHER_GOLD_ORE_PLACE, 0.9f, 1.355f); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1.7f, 0.355f); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BEACON_POWER_SELECT, 0.4f, 0.155f); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 0.2f, 1.455f); + spw.play(player.getLocation(), Sound.BLOCK_NETHER_GOLD_ORE_PLACE, 0.9f, 1.355f); + spw.play(player.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1.7f, 0.355f); + spw.play(player.getLocation(), Sound.BLOCK_BEACON_POWER_SELECT, 0.4f, 0.155f); + spw.play(player.getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 0.2f, 1.455f); if (isPermanent()) { - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.7f, 1.355f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_GOAT_HORN_SOUND_1, 0.7f, 1.355f); + spw.play(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.7f, 1.355f); + spw.play(player.getLocation(), Sound.ITEM_GOAT_HORN_SOUND_1, 0.7f, 1.355f); } w.close(); if (AdaptConfig.get().getLearnUnlearnButtonDelayTicks() != 0) { @@ -470,10 +470,10 @@ default void openGui(Player player) { } J.s(() -> openGui(player), AdaptConfig.get().getLearnUnlearnButtonDelayTicks()); } else { - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BAMBOO_HIT, 0.7f, 1.855f); + spw.play(player.getLocation(), Sound.BLOCK_BAMBOO_HIT, 0.7f, 1.855f); } } else { - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BAMBOO_HIT, 0.7f, 1.855f); + spw.play(player.getLocation(), Sound.BLOCK_BAMBOO_HIT, 0.7f, 1.855f); } }); de.addLore(" "); @@ -501,9 +501,10 @@ default void openGui(Player player) { } private void onGuiClose(Player player, boolean openPrevGui) { - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 0.655f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 0.855f); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 0.655f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 0.855f); if (openPrevGui) { getSkill().openGui(player); } diff --git a/src/main/java/com/volmit/adapt/api/notification/SoundNotification.java b/src/main/java/com/volmit/adapt/api/notification/SoundNotification.java index cf9b4544..633d5772 100644 --- a/src/main/java/com/volmit/adapt/api/notification/SoundNotification.java +++ b/src/main/java/com/volmit/adapt/api/notification/SoundNotification.java @@ -20,6 +20,7 @@ import com.volmit.adapt.api.world.AdaptPlayer; import com.volmit.adapt.util.J; +import com.volmit.adapt.util.SoundPlayer; import lombok.Builder; import lombok.Data; import org.bukkit.Sound; @@ -71,6 +72,6 @@ public String getGroup() { } public void play(AdaptPlayer p) { - J.s(() -> p.getPlayer().playSound(p.getPlayer().getLocation(), sound, volume, pitch)); + SoundPlayer.of(p.getPlayer()).play(p.getPlayer().getLocation(), sound, volume, pitch); } } diff --git a/src/main/java/com/volmit/adapt/api/potion/BrewingTask.java b/src/main/java/com/volmit/adapt/api/potion/BrewingTask.java index 1d40dc4d..66643f90 100644 --- a/src/main/java/com/volmit/adapt/api/potion/BrewingTask.java +++ b/src/main/java/com/volmit/adapt/api/potion/BrewingTask.java @@ -1,6 +1,7 @@ package com.volmit.adapt.api.potion; import com.volmit.adapt.Adapt; +import com.volmit.adapt.util.SoundPlayer; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; @@ -86,7 +87,8 @@ public void run() { inventory.getViewers().forEach(e -> { if (e instanceof Player p) { - p.playSound(block.getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1, 1); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(block.getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1, 1); } }); cancel(); diff --git a/src/main/java/com/volmit/adapt/api/skill/Skill.java b/src/main/java/com/volmit/adapt/api/skill/Skill.java index b3d15159..6bcb7bdd 100644 --- a/src/main/java/com/volmit/adapt/api/skill/Skill.java +++ b/src/main/java/com/volmit/adapt/api/skill/Skill.java @@ -205,9 +205,10 @@ default void openGui(Player player) { return; } - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 1.455f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 1.855f); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 1.455f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 1.855f); Window w = new UIWindow(player); w.setTag("skill/" + getName()); w.setDecorator((window, position, row) -> new UIElement("bg").setName(" ").setMaterial(new MaterialBlock(Material.BLACK_STAINED_GLASS_PANE))); @@ -255,9 +256,10 @@ default void openGui(Player player) { } private void onGuiClose(Player player, boolean openPrevGui) { - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 1.455f); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 1.855f); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1.1f, 1.255f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.7f, 1.455f); + spw.play(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.3f, 1.855f); if (openPrevGui) { SkillsGui.open(player); } diff --git a/src/main/java/com/volmit/adapt/api/skill/SkillRegistry.java b/src/main/java/com/volmit/adapt/api/skill/SkillRegistry.java index d40b8c36..8bf51590 100644 --- a/src/main/java/com/volmit/adapt/api/skill/SkillRegistry.java +++ b/src/main/java/com/volmit/adapt/api/skill/SkillRegistry.java @@ -31,6 +31,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Form; import com.volmit.adapt.util.M; +import com.volmit.adapt.util.SoundPlayer; import com.volmit.adapt.util.reflect.enums.Particles; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -108,8 +109,9 @@ && canInteract(p, e.getClickedBlock().getLocation()) (p.getInventory().getItemInOffHand().getType().equals(Material.AIR) || !p.getInventory().getItemInOffHand().getType().isBlock()); if (isAdaptActivator) { - e.getClickedBlock().getWorld().playSound(e.getClickedBlock().getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.5f, 0.72f); - e.getClickedBlock().getWorld().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 0.35f, 0.755f); + SoundPlayer spw = SoundPlayer.of(e.getClickedBlock().getWorld()); + spw.play(e.getClickedBlock().getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.5f, 0.72f); + spw.play(e.getClickedBlock().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 0.35f, 0.755f); SkillsGui.open(p); e.setCancelled(true); p.getWorld().spawnParticle(Particles.CRIT_MAGIC, e.getClickedBlock().getLocation().clone().add(0.5, 1, 0.5), 25, 0, 0, 0, 1.1); @@ -160,10 +162,11 @@ && canInteract(p, e.getClickedBlock().getLocation()) } private void playDebug(Player p) { - p.playSound(p.getLocation(), Sound.BLOCK_BELL_RESONATE, 1f, 0.6f); - p.playSound(p.getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 1f, 0.1f); - p.playSound(p.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1f, 1.6f); - p.playSound(p.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1f, 1.2f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_BELL_RESONATE, 1f, 0.6f); + sp.play(p.getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 1f, 0.1f); + sp.play(p.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1f, 1.6f); + sp.play(p.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1f, 1.2f); } diff --git a/src/main/java/com/volmit/adapt/api/world/AdaptServer.java b/src/main/java/com/volmit/adapt/api/world/AdaptServer.java index 7f41a166..3f1b50cb 100644 --- a/src/main/java/com/volmit/adapt/api/world/AdaptServer.java +++ b/src/main/java/com/volmit/adapt/api/world/AdaptServer.java @@ -184,11 +184,12 @@ public void on(PlayerQuitEvent e) { @EventHandler public void on(CraftItemEvent e) { if (e.getWhoClicked() instanceof Player p) { + SoundPlayer sp = SoundPlayer.of(p); for (Skill i : getSkillRegistry().getSkills()) { for (Adaptation j : i.getAdaptations()) { if (j.isAdaptationRecipe(e.getRecipe()) && !j.hasAdaptation(p)) { Adapt.actionbar(p, C.RED + "Requires " + j.getDisplayName() + C.RED + " from " + i.getDisplayName()); - p.playSound(p.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.5f, 1.8f); + sp.play(p.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.5f, 1.8f); e.setCancelled(true); } } diff --git a/src/main/java/com/volmit/adapt/command/CommandDebug.java b/src/main/java/com/volmit/adapt/command/CommandDebug.java index acf1d124..c788da0d 100644 --- a/src/main/java/com/volmit/adapt/command/CommandDebug.java +++ b/src/main/java/com/volmit/adapt/command/CommandDebug.java @@ -3,6 +3,7 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.AdaptConfig; import com.volmit.adapt.util.J; +import com.volmit.adapt.util.SoundPlayer; import com.volmit.adapt.util.command.FConst; import com.volmit.adapt.util.decree.DecreeExecutor; import com.volmit.adapt.util.decree.DecreeOrigin; @@ -78,6 +79,7 @@ public void particle(@Param Sound sound) { return; } - player().playSound(player().getLocation(), sound, 1, 1); + SoundPlayer sp = SoundPlayer.of(player()); + sp.play(player().getLocation(), sound, 1, 1); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilitySuperJump.java b/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilitySuperJump.java index 67a73e6b..5bb822c3 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilitySuperJump.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilitySuperJump.java @@ -77,7 +77,8 @@ public void on(PlayerToggleSneakEvent e) { } if (e.isSneaking() && p.isOnGround()) { - p.playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 0.3f, 0.35f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 0.3f, 0.35f); } } @@ -114,8 +115,9 @@ public void on(PlayerMoveEvent e) { lastJump.remove(p); } if (p.getLocation().getBlock().getType() != Material.LADDER && velocity.getY() > jumpVelocity && p.isOnline()) { - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1.25f, 0.7f); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1.25f, 1.7f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1.25f, 0.7f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1.25f, 1.7f); if (getConfig().showParticles) { p.getWorld().spawnParticle(Particles.BLOCK_CRACK, p.getLocation().clone().add(0, 0.3, 0), 15, 0.1, 0.8, 0.1, 0.1, p.getLocation().getBlock().getRelative(BlockFace.DOWN).getBlockData()); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilityWallJump.java b/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilityWallJump.java index 0c997adc..7bdfac57 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilityWallJump.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/agility/AgilityWallJump.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.agility; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import com.volmit.adapt.util.reflect.enums.Particles; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; @@ -131,15 +128,17 @@ public void onTick() { if (!jumped && !p.hasGravity()) { p.setGravity(true); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1f, 0.439f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1f, 0.439f); } continue; } if (canStick(p)) { if (p.hasGravity()) { - p.getLocation().getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1f, 0.89f); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_CHAIN, 1f, 1.39f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 1f, 0.89f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_CHAIN, 1f, 1.39f); if (getConfig().showParticles && getStick(p) != null) { p.getWorld().spawnParticle(Particles.BLOCK_CRACK, p.getLocation().clone().add(0, 0.3, 0), 15, 0.1, 0.2, 0.1, 0.1, getStick(p).getBlockData()); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectFoundation.java b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectFoundation.java index fdd20e6b..f5456d07 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectFoundation.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectFoundation.java @@ -198,8 +198,9 @@ public void on(PlayerToggleSneakEvent e) { } else if (!e.isSneaking() && active) { this.active.remove(p); cooldowns.put(p, M.ms() + getConfig().cooldown); - p.playSound(p.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1.0f, 10.0f); - p.playSound(p.getLocation(), Sound.BLOCK_SCULK_CATALYST_BREAK, 1.0f, 0.81f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1.0f, 10.0f); + sp.play(p.getLocation(), Sound.BLOCK_SCULK_CATALYST_BREAK, 1.0f, 0.81f); } } @@ -212,7 +213,8 @@ public boolean addFoundation(Block block) { block.setBlockData(BLOCK); activeBlocks.add(block); }); - block.getWorld().playSound(block.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.0f, 1.0f); + SoundPlayer spw = SoundPlayer.of(block.getWorld()); + spw.play(block.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.0f, 1.0f); if (getConfig().showParticles) { vfxCuboidOutline(block, Particle.REVERSE_PORTAL); @@ -230,7 +232,8 @@ public void removeFoundation(Block block) { J.s(() -> { block.setBlockData(AIR); activeBlocks.remove(block); - block.getWorld().playSound(block.getLocation(), Sound.BLOCK_DEEPSLATE_BREAK, 1.0f, 1.0f); + SoundPlayer spw = SoundPlayer.of(block.getWorld()); + spw.play(block.getLocation(), Sound.BLOCK_DEEPSLATE_BREAK, 1.0f, 1.0f); }); if (getConfig().showParticles) { vfxCuboidOutline(block, Particles.ENCHANTMENT_TABLE); @@ -258,11 +261,9 @@ public void onTick() { final var world = i.getWorld(); final var location = i.getLocation(); - - J.s(() -> { - world.playSound(location, Sound.BLOCK_BEACON_ACTIVATE, 1.0f, 10.0f); - world.playSound(location, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1.0f, 0.81f); - }); + SoundPlayer spw = SoundPlayer.of(world); + spw.play(location, Sound.BLOCK_BEACON_ACTIVATE, 1.0f, 10.0f); + spw.play(location, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1.0f, 0.81f); return availablePower; } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectGlass.java b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectGlass.java index 1ebb4b92..a80726e2 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectGlass.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectGlass.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.architect; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Particle; @@ -66,7 +63,8 @@ public void on(BlockBreakEvent e) { } if (e.getBlock().getType().toString().contains("GLASS") && !e.getBlock().getType().toString().contains("TINTED_GLASS")) { e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(e.getBlock().getType(), 1)); - e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.BLOCK_LARGE_AMETHYST_BUD_BREAK, 1.0f, 1.0f); + SoundPlayer spw = SoundPlayer.of(e.getBlock().getWorld()); + spw.play(e.getBlock().getLocation(), Sound.BLOCK_LARGE_AMETHYST_BUD_BREAK, 1.0f, 1.0f); if (getConfig().showParticles) { e.getBlock().getWorld().spawnParticle(Particle.SCRAPE, e.getBlock().getLocation(), 1); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectPlacement.java b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectPlacement.java index d7f6db3f..58f52f5b 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectPlacement.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectPlacement.java @@ -20,10 +20,7 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Particle; @@ -85,6 +82,7 @@ public void on(BlockPlaceEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (hasAdaptation(p) && !totalMap.isEmpty() && totalMap.get(p) != null && totalMap.get(p).size() > 0) { ItemStack is = p.getInventory().getItemInMainHand().clone(); @@ -104,7 +102,7 @@ public void on(BlockPlaceEvent e) { b.getWorld().setBlockData(b.getRelative(face).getLocation(), b.getBlockData()); getPlayer(p).getData().addStat("blocks.placed", 1); getPlayer(p).getData().addStat("blocks.placed.value", v); - p.playSound(b.getLocation(), Sound.BLOCK_AZALEA_BREAK, 0.4f, 0.25f); + sp.play(b.getLocation(), Sound.BLOCK_AZALEA_BREAK, 0.4f, 0.25f); xp(p, 2); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectWirelessRedstone.java b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectWirelessRedstone.java index f8a15aa2..14a76601 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectWirelessRedstone.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/architect/ArchitectWirelessRedstone.java @@ -25,11 +25,8 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.api.recipe.AdaptRecipe; import com.volmit.adapt.content.item.BoundRedstoneTorch; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; -import com.volmit.adapt.util.M; +import com.volmit.adapt.util.*; + import java.util.HashMap; import java.util.Map; import lombok.NoArgsConstructor; @@ -149,7 +146,8 @@ private void handleLeftClickBlock(PlayerInteractEvent event, Player player) { } if (event.getClickedBlock() == null) { - player.playSound(player.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.1f, 0.9f); + SoundPlayer sp = SoundPlayer.of(player); + sp.play(player.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.1f, 0.9f); return; } @@ -169,7 +167,8 @@ private void handleRightClick(PlayerInteractEvent event, Player player) { } if (hasCooldown(player)) { - player.playSound(player.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.1f, 0.9f); + SoundPlayer sp = SoundPlayer.of(player); + sp.play(player.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.1f, 0.9f); } else { cooldowns.put(player, System.currentTimeMillis() + getConfig().cooldown); updatePlayerCooldown(player, false); @@ -199,8 +198,9 @@ private void linkTorch(Player p, Location l) { if (getConfig().showParticles) { vfxCuboidOutline(l.getBlock(), l.getBlock(), Color.RED, 1); } - p.getWorld().playSound(l, Sound.BLOCK_CHEST_OPEN, 0.1f, 9f); - p.getWorld().playSound(l, Sound.ENTITY_ENDER_EYE_DEATH, 0.2f, 0.48f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(l, Sound.BLOCK_CHEST_OPEN, 0.1f, 9f); + spw.play(l, Sound.ENTITY_ENDER_EYE_DEATH, 0.2f, 0.48f); ItemStack hand = p.getInventory().getItemInMainHand(); if (hand.getAmount() == 1) { BoundRedstoneTorch.setData(hand, l); @@ -219,7 +219,8 @@ private void triggerPulse(Player p, ItemStack item) { Block b = l.getBlock(); BlockData data = b.getBlockData(); if (data instanceof AnaloguePowerable redBlock && b.getType().equals(Material.TARGET)) { - p.getWorld().playSound(l, Sound.BLOCK_CHEST_OPEN, 0.1f, 9f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(l, Sound.BLOCK_CHEST_OPEN, 0.1f, 9f); redBlock.setPower(15); vfxCuboidOutline(l.getBlock(), l.getBlock(), Color.RED, 1); b.setBlockData(redBlock); @@ -228,7 +229,8 @@ private void triggerPulse(Player p, ItemStack item) { b.setBlockData(redBlock); }, 2); } else { - p.playSound(p.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.1f, 0.9f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 0.1f, 0.9f); } }); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeChop.java b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeChop.java index 697c5934..9a1ab365 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeChop.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeChop.java @@ -20,10 +20,7 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -72,7 +69,8 @@ public void on(PlayerInteractEvent e) { BlockData b = e.getClickedBlock().getBlockData(); if (isLog(new ItemStack(b.getMaterial()))) { e.setCancelled(true); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.ITEM_AXE_STRIP, 1.25f, 0.6f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_AXE_STRIP, 1.25f, 0.6f); for (int i = 0; i < getLevel(p); i++) { if (breakStuff(e.getClickedBlock(), getRange(getLevel(p)), p)) { p.setCooldown(p.getInventory().getItemInMainHand().getType(), getCooldownTime(getLevelPercent(p))); @@ -116,7 +114,9 @@ private boolean breakStuff(Block b, int power, Player player) { } Block ll = last; - b.getWorld().playSound(ll.getLocation(), Sound.ITEM_AXE_STRIP, 0.75f, 1.3f); + + SoundPlayer spw = SoundPlayer.of(b.getWorld()); + spw.play(ll.getLocation(), Sound.ITEM_AXE_STRIP, 0.75f, 1.3f); player.breakBlock(ll); return true; diff --git a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeDropToInventory.java b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeDropToInventory.java index ef7bc727..a797e70d 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeDropToInventory.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeDropToInventory.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.GameMode; import org.bukkit.Material; @@ -65,6 +66,7 @@ public void on(BlockDropItemEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } @@ -78,7 +80,7 @@ public void on(BlockDropItemEvent e) { List items = e.getItems().copy(); e.getItems().clear(); for (Item i : items) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); if (!p.getInventory().addItem(i.getItemStack()).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i.getItemStack()); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeGroundSmash.java b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeGroundSmash.java index 8cc622d1..4fbea5ec 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeGroundSmash.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeGroundSmash.java @@ -78,10 +78,10 @@ public void on(EntityDamageByEntityEvent e) { .damage(getDamage(f), getFalloffDamage(f)) .force(getForce(f)) .punch(e.getEntity().getLocation()); - e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, SoundCategory.HOSTILE, 0.6f, 0.4f); - e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, SoundCategory.HOSTILE, 0.5f, 0.1f); - e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENTITY_TURTLE_EGG_CRACK, SoundCategory.HOSTILE, 1f, 0.4f); - + SoundPlayer spw = SoundPlayer.of(e.getEntity().getWorld()); + spw.play(e.getEntity().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, SoundCategory.HOSTILE, 0.6f, 0.4f); + spw.play(e.getEntity().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, SoundCategory.HOSTILE, 0.5f, 0.1f); + spw.play(e.getEntity().getLocation(), Sound.ENTITY_TURTLE_EGG_CRACK, SoundCategory.HOSTILE, 1f, 0.4f); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeLeafVeinminer.java b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeLeafVeinminer.java index e05ade8e..eecbc4cf 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeLeafVeinminer.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeLeafVeinminer.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.axe; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import com.volmit.adapt.util.reflect.enums.Particles; import lombok.NoArgsConstructor; import org.bukkit.Location; @@ -74,6 +71,7 @@ public void on(BlockBreakEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (hasAdaptation(p)) { if (!p.isSneaking()) { return; @@ -111,7 +109,7 @@ public void on(BlockBreakEvent e) { if (getPlayer(p).getData().getSkillLines() != null && getPlayer(p).getData().getSkillLines().get("axes").getAdaptations() != null && getPlayer(p).getData().getSkillLines().get("axes").getAdaptations().get("axe-drop-to-inventory") == null && getPlayer(p).getData().getSkillLines().get("axes").getAdaptations().get("axe-drop-to-inventory").getLevel() > 0) { Collection items = e.getBlock().getDrops(); for (ItemStack i : items) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.01f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.01f, 0.01f); HashMap extra = p.getInventory().addItem(i); if (!extra.isEmpty()) { p.getWorld().dropItem(p.getLocation(), extra.get(0)); @@ -120,7 +118,8 @@ public void on(BlockBreakEvent e) { p.breakBlock(l.getBlock()); } else { b.breakNaturally(p.getItemInUse()); - e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.BLOCK_FUNGUS_BREAK, 0.01f, 0.25f); + SoundPlayer spw = SoundPlayer.of(e.getBlock().getWorld()); + spw.play(e.getBlock().getLocation(), Sound.BLOCK_FUNGUS_BREAK, 0.01f, 0.25f); if (getConfig().showParticles) { e.getBlock().getWorld().spawnParticle(Particle.ASH, e.getBlock().getLocation().add(0.5, 0.5, 0.5), 25, 0.5, 0.5, 0.5, 0.1); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeWoodVeinminer.java b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeWoodVeinminer.java index d383b703..9d59e72c 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeWoodVeinminer.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/axe/AxeWoodVeinminer.java @@ -20,10 +20,7 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import com.volmit.adapt.util.reflect.enums.Particles; import lombok.NoArgsConstructor; import org.bukkit.Material; @@ -127,7 +124,8 @@ public void on(BlockBreakEvent e) { blocks.setType(Material.AIR); } else { blocks.breakNaturally(p.getItemInUse()); - blocks.getWorld().playSound(e.getBlock().getLocation(), Sound.BLOCK_FUNGUS_BREAK, 0.01f, 0.25f); + SoundPlayer spw = SoundPlayer.of(blocks.getWorld()); + spw.play(e.getBlock().getLocation(), Sound.BLOCK_FUNGUS_BREAK, 0.01f, 0.25f); if (getConfig().showParticles) { blocks.getWorld().spawnParticle(Particle.ASH, blocks.getLocation().add(0.5, 0.5, 0.5), 25, 0.5, 0.5, 0.5, 0.1); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/blocking/BlockingMultiArmor.java b/src/main/java/com/volmit/adapt/content/adaptation/blocking/BlockingMultiArmor.java index af5adae3..4d950ef9 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/blocking/BlockingMultiArmor.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/blocking/BlockingMultiArmor.java @@ -21,10 +21,7 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.content.item.ItemListings; import com.volmit.adapt.content.item.multiItems.MultiArmor; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -99,14 +96,15 @@ public void on(PlayerMoveEvent e) { else cooldowns.remove(p); } + SoundPlayer spw = SoundPlayer.of(p.getWorld()); if (p.isOnGround() && !p.isFlying()) { if (isChestplate(chest)) { return; } J.s(() -> p.getInventory().setChestplate(multiarmor.nextChestplate(chest))); cooldowns.put(p, System.currentTimeMillis()); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); - p.getWorld().playSound(p.getLocation(), Sound.BLOCK_BEEHIVE_SHEAR, 0.5f, 0.77f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + spw.play(p.getLocation(), Sound.BLOCK_BEEHIVE_SHEAR, 0.5f, 0.77f); } else if (p.getFallDistance() > 4) { if (isElytra(chest)) { @@ -114,8 +112,8 @@ public void on(PlayerMoveEvent e) { } J.s(() -> p.getInventory().setChestplate(multiarmor.nextElytra(chest))); cooldowns.put(p, System.currentTimeMillis()); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.5f, 0.77f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + spw.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.5f, 0.77f); } } } @@ -124,6 +122,7 @@ public void on(PlayerMoveEvent e) { @EventHandler(priority = EventPriority.HIGHEST) public void on(PlayerDropItemEvent e) { Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } @@ -154,7 +153,7 @@ public void on(PlayerDropItemEvent e) { } J.s(() -> { - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_DEATH, 0.25f, 0.77f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_DEATH, 0.25f, 0.77f); for (ItemStack i : drops) { p.getWorld().dropItem(p.getLocation(), i); } @@ -183,7 +182,8 @@ public void on(InventoryClickEvent e) { if (multiarmor.explode(cursor).size() >= getSlots(getLevel((Player) e.getWhoClicked())) || multiarmor.explode(clicked).size() >= getSlots(getLevel((Player) e.getWhoClicked()))) { e.setCancelled(true); - ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1f, 0.77f); + SoundPlayer sp = SoundPlayer.of((Player) e.getWhoClicked()); + sp.play(e.getWhoClicked().getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1f, 0.77f); return; } } @@ -193,7 +193,8 @@ public void on(InventoryClickEvent e) { e.setCancelled(true); e.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR)); e.getClickedInventory().setItem(e.getSlot(), multiarmor.build(cursor, clicked)); - e.getWhoClicked().getWorld().playSound(e.getWhoClicked().getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + SoundPlayer spw = SoundPlayer.of(e.getWhoClicked().getWorld()); + spw.play(e.getWhoClicked().getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); } } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingLingering.java b/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingLingering.java index 9c733459..169f6852 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingLingering.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingLingering.java @@ -98,8 +98,9 @@ public void on(BrewEvent e) { if (ef) { ((BrewingStand) e.getBlock().getState()).getInventory().setStorageContents(c); - e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1f, 0.75f); - e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1f, 1.75f); + SoundPlayer spw = SoundPlayer.of(e.getBlock().getWorld()); + spw.play(e.getBlock().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1f, 0.75f); + spw.play(e.getBlock().getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1f, 1.75f); } }); } else { diff --git a/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingSuperHeated.java b/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingSuperHeated.java index 6d6d4884..5f1b52c9 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingSuperHeated.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/brewing/BrewingSuperHeated.java @@ -190,7 +190,8 @@ private void updateHeat(BrewingStand b, double factor) { b.update(); if (M.r(1D / (333D / getInterval()))) { - b.getBlock().getWorld().playSound(b.getBlock().getLocation(), Sound.BLOCK_FIRE_AMBIENT, 1f, 1f + RNG.r.f(0.3f, 0.6f)); + SoundPlayer spw = SoundPlayer.of(b.getBlock().getWorld()); + spw.play(b.getBlock().getLocation(), Sound.BLOCK_FIRE_AMBIENT, 1f, 1f + RNG.r.f(0.3f, 0.6f)); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingDeconstruction.java b/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingDeconstruction.java index a775a810..09d272a5 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingDeconstruction.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingDeconstruction.java @@ -22,6 +22,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -145,10 +146,11 @@ private void processItemInteraction(Player player, ItemStack mainHandItem, Item ItemStack forStuff = itemEntity.getItemStack(); ItemStack offering = getDeconstructionOffering(forStuff); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); if (offering != null) { itemEntity.setItemStack(offering); - player.getWorld().playSound(itemEntity.getLocation(), Sound.BLOCK_BASALT_BREAK, 1F, 0.2f); - player.getWorld().playSound(itemEntity.getLocation(), Sound.BLOCK_BEEHIVE_SHEAR, 1F, 0.7f); + spw.play(itemEntity.getLocation(), Sound.BLOCK_BASALT_BREAK, 1F, 0.2f); + spw.play(itemEntity.getLocation(), Sound.BLOCK_BEEHIVE_SHEAR, 1F, 0.7f); getSkill().xp(player, getValue(offering)); // Damage the shears @@ -161,7 +163,7 @@ private void processItemInteraction(Player player, ItemStack mainHandItem, Item mainHandItem.setItemMeta(damageable); } } else { - player.getWorld().playSound(itemEntity.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 1F, 1f); // Burnt torch sound + spw.play(itemEntity.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 1F, 1f); // Burnt torch sound } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingStations.java b/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingStations.java index c013589e..d3ca9058 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingStations.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/crafting/CraftingStations.java @@ -22,6 +22,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -71,45 +72,46 @@ public void on(PlayerInteractEvent e) { if ((e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK))) { + SoundPlayer sp = SoundPlayer.of(p); switch (hand.getType()) { case CRAFTING_TABLE -> { p.setCooldown(hand.getType(), 1000); - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); p.openWorkbench(null, true); } case GRINDSTONE -> { p.setCooldown(hand.getType(), 1000); - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); Inventory inv = Bukkit.createInventory(p, InventoryType.GRINDSTONE); p.openInventory(inv); } case ANVIL -> { p.setCooldown(hand.getType(), 1000); - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); Inventory inv = Bukkit.createInventory(p, InventoryType.ANVIL); p.openInventory(inv); } case STONECUTTER -> { p.setCooldown(hand.getType(), 1000); - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); Inventory inv = Bukkit.createInventory(p, InventoryType.STONECUTTER); p.openInventory(inv); } case CARTOGRAPHY_TABLE -> { p.setCooldown(hand.getType(), 1000); - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); Inventory inv = Bukkit.createInventory(p, InventoryType.CARTOGRAPHY); p.openInventory(inv); } case LOOM -> { p.setCooldown(hand.getType(), 1000); - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); Inventory inv = Bukkit.createInventory(p, InventoryType.LOOM); p.openInventory(inv); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryUnity.java b/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryUnity.java index 9f62bc7c..39f6b42f 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryUnity.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryUnity.java @@ -22,10 +22,7 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.api.world.AdaptPlayer; import com.volmit.adapt.api.world.PlayerSkillLine; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -61,10 +58,11 @@ public void addStats(int level, Element v) { @EventHandler(priority = EventPriority.LOW) public void on(PlayerExpChangeEvent e) { Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); AdaptPlayer ap = getPlayer(p); if (hasAdaptation(p) && e.getAmount() > 0) { xp(p, 5); - p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1.9f); + sp.play(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1.9f); //get a random skill that they have unlocked already List skills = ap.getData().getSkillLines().sortV(); if (skills.size() > 0) { diff --git a/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryVillagerAtt.java b/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryVillagerAtt.java index 037ffc1c..2ba9c709 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryVillagerAtt.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryVillagerAtt.java @@ -20,10 +20,7 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import de.slikey.effectlib.effect.BleedEffect; import lombok.NoArgsConstructor; import org.bukkit.Material; @@ -74,6 +71,7 @@ public void on(PlayerInteractEntityEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (e.getRightClicked() instanceof Villager v && hasAdaptation(p)) { Random r = new Random(); if (r.nextDouble() <= getEffectiveness(getLevelPercent(getLevel(p)))) { @@ -82,15 +80,15 @@ public void on(PlayerInteractEntityEvent e) { blood.material = Material.EMERALD; blood.setEntity(v); p.setLevel((p.getLevel() - getXpTaken(getLevel(p)))); - p.playSound(p.getLocation(), Sound.ENTITY_VILLAGER_CELEBRATE, 1f, 1f); - p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f); + sp.play(p.getLocation(), Sound.ENTITY_VILLAGER_CELEBRATE, 1f, 1f); + sp.play(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f); p.addPotionEffect(new PotionEffect(PotionEffectType.HERO_OF_THE_VILLAGE, 10, getLevel(p), true, true)); } else { BleedEffect blood = new BleedEffect(Adapt.instance.adaptEffectManager); // Enemy gets blood blood.material = Material.STONE; v.shakeHead(); blood.setEntity(v); - p.playSound(p.getLocation(), Sound.ENTITY_VILLAGER_NO, 1f, 1f); + sp.play(p.getLocation(), Sound.ENTITY_VILLAGER_NO, 1f, 1f); } } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryXpResist.java b/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryXpResist.java index d39881ad..97e5792f 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryXpResist.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/discovery/DiscoveryXpResist.java @@ -71,9 +71,10 @@ public void on(EntityDamageEvent e) { return; } if (e.getEntity() instanceof Player p && hasAdaptation(p) && p.getLevel() > 1) { + SoundPlayer sp = SoundPlayer.of(p); if (p.getLevel() < p.getLevel() - getXpTaken(getLevel(p))) { vfxFastRing(p.getLocation().add(0, 0.05, 0), 1, Color.RED); - p.playSound(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 15, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 15, 0.01f); return; } Long cooldown = cooldowns.get(p); @@ -84,15 +85,15 @@ public void on(EntityDamageEvent e) { if (p.getLevel() - getXpTaken(getLevel(p)) > 0) { p.setLevel(p.getLevel() - getXpTaken(getLevel(p))); vfxFastRing(p.getLocation().add(0, 0.05, 0), 1, Color.LIME); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_REPAIR, 3, 0.01f); - p.playSound(p.getLocation(), Sound.BLOCK_SHROOMLIGHT_HIT, 15, 0.01f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_REPAIR, 3, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_SHROOMLIGHT_HIT, 15, 0.01f); } else { vfxFastRing(p.getLocation().add(0, 0.05, 0), 1, Color.RED); - p.playSound(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 15, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 15, 0.01f); } } else { vfxFastRing(p.getLocation().add(0, 0.05, 0), 1, Color.RED); - p.playSound(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 15, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 15, 0.01f); } } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/enchanting/EnchantingQuickEnchant.java b/src/main/java/com/volmit/adapt/content/adaptation/enchanting/EnchantingQuickEnchant.java index c81fefb9..fa4bc6bd 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/enchanting/EnchantingQuickEnchant.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/enchanting/EnchantingQuickEnchant.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -115,9 +116,10 @@ && hasAdaptation(p) bookEnchants.remove(i); } + SoundPlayer sp = SoundPlayer.of(p); if (power > getTotalLevelCount(getLevel(p))) { Adapt.actionbar(p, C.RED + Localizer.dLocalize("enchanting", "quickenchant", "lore2") + getTotalLevelCount(getLevel(p)) + " " + Localizer.dLocalize("enchanting", "quickenchant", "lore3")); - p.playSound(p.getLocation(), Sound.BLOCK_CONDUIT_DEACTIVATE, 0.5f, 1.7f); + sp.play(p.getLocation(), Sound.BLOCK_CONDUIT_DEACTIVATE, 0.5f, 1.7f); return; } @@ -138,8 +140,8 @@ && hasAdaptation(p) item.setItemMeta(im); e.setCurrentItem(item); e.setCancelled(true); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.7f); - p.playSound(p.getLocation(), Sound.BLOCK_DEEPSLATE_TILES_BREAK, 0.5f, 0.7f); + sp.play(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.7f); + sp.play(p.getLocation(), Sound.BLOCK_DEEPSLATE_TILES_BREAK, 0.5f, 0.7f); getSkill().xp(p, 320 * addEnchants.values().stream().mapToInt((i) -> i).sum()); if (bookEnchants.isEmpty()) { diff --git a/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationDropToInventory.java b/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationDropToInventory.java index fadb968b..2c080031 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationDropToInventory.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationDropToInventory.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.GameMode; import org.bukkit.Material; @@ -66,6 +67,7 @@ public void on(BlockDropItemEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } @@ -82,7 +84,7 @@ public void on(BlockDropItemEvent e) { List items = e.getItems().copy(); e.getItems().clear(); for (Item i : items) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); xp(p, 2); if (!p.getInventory().addItem(i.getItemStack()).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i.getItemStack()); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationOmniTool.java b/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationOmniTool.java index 45a31e5b..0e82db39 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationOmniTool.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationOmniTool.java @@ -22,10 +22,7 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.content.item.ItemListings; import com.volmit.adapt.content.item.multiItems.OmniTool; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -118,11 +115,13 @@ public void on(EntityDamageByEntityEvent e) { return; } J.s(() -> p.getInventory().setItemInMainHand(omniTool.nextSword(hand))); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); if (inHand != null && inHand.hasDamage()) { if ((hand.getType().getMaxDurability() - inHand.getDamage() - 2) <= 2) { e.setCancelled(true); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); } } @@ -166,27 +165,29 @@ public void on(PlayerInteractEvent e) { Damageable imHand = (Damageable) hand.getItemMeta(); Block block = e.getClickedBlock(); if (block != null) { + SoundPlayer sp = SoundPlayer.of(p); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); if (ItemListings.farmable.contains(block.getType())) { if (isShovel(hand)) { J.s(() -> p.getInventory().setItemInMainHand(omniTool.nextHoe(hand))); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); } else { J.s(() -> p.getInventory().setItemInMainHand(omniTool.nextShovel(hand))); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); } if (imHand != null && imHand.hasDamage()) { if ((hand.getType().getMaxDurability() - imHand.getDamage() - 2) <= 2) { e.setCancelled(true); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); } } } else if (ItemListings.burnable.contains(block.getType())) { J.s(() -> p.getInventory().setItemInMainHand(omniTool.nextFnS(hand))); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); if (imHand != null && imHand.hasDamage()) { if ((hand.getType().getMaxDurability() - imHand.getDamage() - 2) <= 2) { e.setCancelled(true); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); } } } @@ -229,7 +230,8 @@ public void on(PlayerDropItemEvent e) { } J.s(() -> { - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_DEATH, 0.25f, 0.77f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_DEATH, 0.25f, 0.77f); for (ItemStack i : drops) { p.getWorld().dropItem(p.getLocation(), i); } @@ -301,7 +303,8 @@ public void on(InventoryClickEvent e) { if (omniTool.explode(cursor).size() > 1 || omniTool.explode(clicked).size() > 1) { if (omniTool.explode(cursor).size() >= getSlots(getLevel((Player) e.getWhoClicked())) || omniTool.explode(clicked).size() >= getSlots(getLevel((Player) e.getWhoClicked()))) { e.setCancelled(true); - ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1f, 0.77f); + SoundPlayer sp = SoundPlayer.of((Player) e.getWhoClicked()); + sp.play(e.getWhoClicked().getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1f, 0.77f); return; } } @@ -310,7 +313,8 @@ public void on(InventoryClickEvent e) { e.setCancelled(true); e.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR)); e.getClickedInventory().setItem(e.getSlot(), omniTool.build(cursor, clicked)); - e.getWhoClicked().getWorld().playSound(e.getWhoClicked().getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + SoundPlayer spw = SoundPlayer.of(e.getWhoClicked().getWorld()); + spw.play(e.getWhoClicked().getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); } } } @@ -319,11 +323,13 @@ public void on(InventoryClickEvent e) { private void itemDelegate(BlockDamageEvent e, ItemStack hand, Damageable imHand) { Player p = e.getPlayer(); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); + SoundPlayer sp = SoundPlayer.of(p); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_ELYTRA, 1f, 0.77f); if (imHand != null && imHand.hasDamage()) { if ((hand.getType().getMaxDurability() - imHand.getDamage() - 2) <= 2) { e.setCancelled(true); - p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); + sp.play(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.77f); } } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationSpelunker.java b/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationSpelunker.java index a184f74e..c787f991 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationSpelunker.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/excavation/ExcavationSpelunker.java @@ -22,10 +22,7 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.content.item.ItemListings; import com.volmit.adapt.nms.GlowingEntities; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import com.volmit.adapt.util.reflect.enums.Particles; import lombok.NoArgsConstructor; import org.bukkit.*; @@ -73,12 +70,13 @@ public void addStats(int level, Element v) { @EventHandler(priority = EventPriority.HIGH) public void on(PlayerToggleSneakEvent e) { Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); // Check if player is sneaking, has Glowberries in main hand, and an ore in offhand if (p.isSneaking() && hasGlowberries(p) && hasOreInOffhand(p) && hasAdaptation(p)) { // Check if player is on cooldown Long cooldown = cooldowns.get(p); if (cooldown != null && cooldown > System.currentTimeMillis()) { - p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); + sp.play(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); return; } int radius = getConfig().rangeMultiplier * getLevel(p); @@ -130,8 +128,8 @@ private void searchForOres(Player p, int radius) { } J.s(() -> { - - world.playSound(block.getLocation().add(0.5, 0, 0.5), Sound.BLOCK_BEACON_ACTIVATE, 1, 1); + SoundPlayer spw = SoundPlayer.of(world); + spw.play(block.getLocation().add(0.5, 0, 0.5), Sound.BLOCK_BEACON_ACTIVATE, 1, 1); Slime slime = block.getWorld().spawn(block.getLocation().add(0.5, 0, 0.5), Slime.class, (s) -> { s.setRotation(0, 0); s.setInvulnerable(true); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismDropToInventory.java b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismDropToInventory.java index 1fa445b4..dac0320d 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismDropToInventory.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismDropToInventory.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.GameMode; import org.bukkit.Material; @@ -65,6 +66,7 @@ public void on(BlockDropItemEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } @@ -75,7 +77,7 @@ public void on(BlockDropItemEvent e) { List items = e.getItems().copy(); e.getItems().clear(); for (Item i : items) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); xp(p, 2); if (!p.getInventory().addItem(i.getItemStack()).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i.getItemStack()); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismGrowthAura.java b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismGrowthAura.java index f4be2278..3a415c1b 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismGrowthAura.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismGrowthAura.java @@ -85,6 +85,7 @@ public void onTick() { for (int i = 0; i < Math.min(Math.min(rad * rad, 256), 3); i++) { Location m = p.getLocation().clone().add(new Vector(Math.sin(angle), RNG.r.i(-1, 1), Math.cos(angle)).multiply(Math.random() * rad)); Block a = m.getWorld().getHighestBlockAt(m).getRelative(BlockFace.UP); + SoundPlayer spw = SoundPlayer.of(a.getWorld()); if (a.getBlockData() instanceof Ageable) { Ageable ab = (Ageable) a.getBlockData(); int toGrowLeft = ab.getMaximumAge() - ab.getAge(); @@ -101,7 +102,7 @@ public void onTick() { if (aab.getAge() < aab.getMaximumAge()) { aab.setAge(aab.getAge() + 1); a.setBlockData(aab, true); - a.getWorld().playSound(a.getLocation(), Sound.BLOCK_CHORUS_FLOWER_DEATH, 0.25f, RNG.r.f(0.3f, 0.7f)); + spw.play(a.getLocation(), Sound.BLOCK_CHORUS_FLOWER_DEATH, 0.25f, RNG.r.f(0.3f, 0.7f)); if (getConfig().showParticles) { p.spawnParticle(Particles.VILLAGER_HAPPY, a.getLocation().clone().add(0.5, 0.5, 0.5), 3, 0.3, 0.3, 0.3, 0.9); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismHungryHippo.java b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismHungryHippo.java index 4fb1a983..c595a21e 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismHungryHippo.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismHungryHippo.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.Color; import org.bukkit.Material; @@ -58,12 +59,13 @@ public void on(PlayerItemConsumeEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } if (ItemListings.getFood().contains(e.getItem().getType())) { p.setFoodLevel(p.getFoodLevel() + 2 + getLevel(p)); - p.playSound(p.getLocation(), Sound.BLOCK_POINTED_DRIPSTONE_LAND, 1, 0.25f); + sp.play(p.getLocation(), Sound.BLOCK_POINTED_DRIPSTONE_LAND, 1, 0.25f); vfxFastRing(p.getLocation().add(0, 0.25, 0), 2, Color.GREEN); xp(p, 5); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismReplant.java b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismReplant.java index b154f1f4..30cd05c1 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismReplant.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/herbalism/HerbalismReplant.java @@ -72,6 +72,7 @@ private float getRadius(int lvl) { @EventHandler(priority = EventPriority.HIGHEST) public void on(PlayerInteractEvent e) { Player p = e.getPlayer(); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); if (e.getClickedBlock() == null) { return; } @@ -111,8 +112,8 @@ public void on(PlayerInteractEvent e) { for (Block i : c) { J.s(() -> hit(p, i), M.irand(1, 6)); } - p.getWorld().playSound(p.getLocation(), Sound.ITEM_SHOVEL_FLATTEN, 1f, 0.66f); - p.getWorld().playSound(p.getLocation(), Sound.BLOCK_BAMBOO_SAPLING_BREAK, 1f, 0.66f); + spw.play(p.getLocation(), Sound.ITEM_SHOVEL_FLATTEN, 1f, 0.66f); + spw.play(p.getLocation(), Sound.BLOCK_BAMBOO_SAPLING_BREAK, 1f, 0.66f); if (getConfig().showParticles) { p.spawnParticle(Particles.VILLAGER_HAPPY, p.getLocation().clone().add(0.5, 0.5, 0.5), getLevel(p) * 3, 0.3 * getLevel(p), 0.3 * getLevel(p), 0.3 * getLevel(p), 0.9); } @@ -132,8 +133,9 @@ private void hit(Player p, Block b) { xp(p, b.getLocation().clone().add(0.5, 0.5, 0.5), ((SkillHerbalism.Config) getSkill().getConfig()).plantCropSeedsXP); if (getPlayer(p).getData().getSkillLines().get("herbalism").getAdaptations().get("herbalism-drop-to-inventory") != null && getPlayer(p).getData().getSkillLines().get("herbalism").getAdaptations().get("herbalism-drop-to-inventory").getLevel() > 0) { Collection items = b.getDrops(); + SoundPlayer sp = SoundPlayer.of(p); for (ItemStack i : items) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); i.setAmount(1); if (!p.getInventory().addItem(i).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i); @@ -153,7 +155,8 @@ private void hit(Player p, Block b) { getPlayer(p).getData().addStat("harvest.planted", 1); if (M.r(1D / (double) getLevel(p))) { - p.getWorld().playSound(b.getLocation(), Sound.ITEM_CROP_PLANT, 1f, 0.7f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(b.getLocation(), Sound.ITEM_CROP_PLANT, 1f, 0.7f); } } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/hunter/HunterDropToInventory.java b/src/main/java/com/volmit/adapt/content/adaptation/hunter/HunterDropToInventory.java index cf4c4292..6144969f 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/hunter/HunterDropToInventory.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/hunter/HunterDropToInventory.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.GameMode; import org.bukkit.Material; @@ -68,6 +69,7 @@ public void on(BlockDropItemEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } @@ -83,7 +85,7 @@ public void on(BlockDropItemEvent e) { if (ItemListings.toolSwords.contains(p.getInventory().getItemInMainHand().getType())) { List items = e.getItems().copy(); e.getItems().clear(); - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); for (Item i : items) { if (!p.getInventory().addItem(i.getItemStack()).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i.getItemStack()); @@ -106,7 +108,8 @@ public void on(EntityDeathEvent e) { return; } if (e.getEntity().getKiller() != null && e.getEntity().getKiller().getClass().getSimpleName().equals("CraftPlayer")) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); e.getDrops().forEach(i -> { if (!p.getInventory().addItem(i).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/nether/NetherSkullYeet.java b/src/main/java/com/volmit/adapt/content/adaptation/nether/NetherSkullYeet.java index 875fa2ac..4b693576 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/nether/NetherSkullYeet.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/nether/NetherSkullYeet.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.nether; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Localizer; -import com.volmit.adapt.util.M; +import com.volmit.adapt.util.*; import lombok.Data; import lombok.NoArgsConstructor; import org.bukkit.GameMode; @@ -93,9 +90,10 @@ public void onRightClick(PlayerInteractEvent e) { } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (lastJump.get(p) != null && M.ms() - lastJump.get(p) <= getCooldownDuration(p)) { - p.playSound(p, Sound.BLOCK_CONDUIT_DEACTIVATE, 1F, 1F); + sp.play(p, Sound.BLOCK_CONDUIT_DEACTIVATE, 1F, 1F); return; } @@ -105,7 +103,7 @@ public void onRightClick(PlayerInteractEvent e) { if (p.hasCooldown(p.getInventory().getItemInMainHand().getType())) { e.setCancelled(true); - p.playSound(p, Sound.BLOCK_CONDUIT_DEACTIVATE, 1F, 1F); + sp.play(p, Sound.BLOCK_CONDUIT_DEACTIVATE, 1F, 1F); return; } else { p.setCooldown(Material.WITHER_SKELETON_SKULL, getCooldownDuration(p)); @@ -120,7 +118,7 @@ public void onRightClick(PlayerInteractEvent e) { Vector dir = p.getEyeLocation().getDirection(); Location spawn = p.getEyeLocation().add(new Vector(.5, -.5, .5)).add(dir); p.getWorld().spawn(spawn, WitherSkull.class, entity -> { - p.playSound(entity, Sound.ENTITY_WITHER_SHOOT, 1, 1); + sp.play(entity, Sound.ENTITY_WITHER_SHOOT, 1, 1); entity.setRotation(p.getEyeLocation().getYaw(), p.getEyeLocation().getPitch()); entity.setCharged(false); entity.setBounce(false); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeAutosmelt.java b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeAutosmelt.java index 85abe29f..1cec5874 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeAutosmelt.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeAutosmelt.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import com.volmit.adapt.util.reflect.enums.Enchantments; import lombok.NoArgsConstructor; import org.bukkit.Material; @@ -56,6 +57,7 @@ public PickaxeAutosmelt() { static void autosmeltBlockDTI(Block b, Player p) { int fortune = getFortuneOreMultiplier(p.getInventory().getItemInMainHand() .getEnchantments().get(Enchantments.LOOT_BONUS_BLOCKS)); + SoundPlayer spw = SoundPlayer.of(b.getWorld()); switch (b.getType()) { case IRON_ORE, DEEPSLATE_IRON_ORE -> { if (b.getLocation().getWorld() == null) { @@ -65,7 +67,7 @@ static void autosmeltBlockDTI(Block b, Player p) { b.setType(Material.AIR); HashMap excessItems = p.getInventory().addItem(new ItemStack(Material.IRON_INGOT, fortune)); excessItems.values().forEach(itemStack -> b.getLocation().getWorld().dropItemNaturally(b.getLocation(), itemStack)); - b.getWorld().playSound(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); + spw.play(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); b.getWorld().spawnParticle(Particle.LAVA, b.getLocation(), 3, 0.5, 0.5, 0.5); } case GOLD_ORE, DEEPSLATE_GOLD_ORE -> { @@ -76,7 +78,7 @@ static void autosmeltBlockDTI(Block b, Player p) { b.setType(Material.AIR); HashMap excessItems = p.getInventory().addItem(new ItemStack(Material.GOLD_INGOT, fortune)); excessItems.values().forEach(itemStack -> b.getLocation().getWorld().dropItemNaturally(b.getLocation(), itemStack)); - b.getWorld().playSound(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); + spw.play(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); b.getWorld().spawnParticle(Particle.LAVA, b.getLocation(), 3, 0.5, 0.5, 0.5); } case COPPER_ORE, DEEPSLATE_COPPER_ORE -> { @@ -86,7 +88,7 @@ static void autosmeltBlockDTI(Block b, Player p) { b.setType(Material.AIR); HashMap excessItems = p.getInventory().addItem(new ItemStack(Material.COPPER_INGOT, fortune)); excessItems.values().forEach(itemStack -> b.getLocation().getWorld().dropItemNaturally(b.getLocation(), itemStack)); - b.getWorld().playSound(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); + spw.play(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); b.getWorld().spawnParticle(Particle.LAVA, b.getLocation(), 3, 0.5, 0.5, 0.5); } @@ -96,6 +98,7 @@ static void autosmeltBlockDTI(Block b, Player p) { static void autosmeltBlock(Block b, Player p) { int fortune = getFortuneOreMultiplier(p.getInventory().getItemInMainHand() .getEnchantments().get(Enchantments.LOOT_BONUS_BLOCKS)); + SoundPlayer spw = SoundPlayer.of(b.getWorld()); switch (b.getType()) { case IRON_ORE, DEEPSLATE_IRON_ORE -> { @@ -105,7 +108,7 @@ static void autosmeltBlock(Block b, Player p) { b.setType(Material.AIR); b.getLocation().getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.IRON_INGOT, fortune)); - b.getWorld().playSound(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); + spw.play(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); b.getWorld().spawnParticle(Particle.LAVA, b.getLocation(), 3, 0.5, 0.5, 0.5); } case GOLD_ORE, DEEPSLATE_GOLD_ORE -> { @@ -115,7 +118,7 @@ static void autosmeltBlock(Block b, Player p) { b.setType(Material.AIR); b.getLocation().getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.GOLD_INGOT, fortune)); - b.getWorld().playSound(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); + spw.play(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); b.getWorld().spawnParticle(Particle.LAVA, b.getLocation(), 3, 0.5, 0.5, 0.5); } case COPPER_ORE, DEEPSLATE_COPPER_ORE -> { @@ -124,7 +127,7 @@ static void autosmeltBlock(Block b, Player p) { } b.setType(Material.AIR); b.getLocation().getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.COPPER_INGOT, fortune)); - b.getWorld().playSound(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); + spw.play(b.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); b.getWorld().spawnParticle(Particle.LAVA, b.getLocation(), 3, 0.5, 0.5, 0.5); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeChisel.java b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeChisel.java index 92ce90db..234f0ff8 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeChisel.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeChisel.java @@ -86,8 +86,9 @@ public void on(PlayerInteractEvent e) { } BlockData b = e.getClickedBlock().getBlockData(); if (isOre(b)) { - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.25f, 1.4f); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_METAL_HIT, 1.25f, 1.7f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.25f, 1.4f); + spw.play(p.getLocation(), Sound.BLOCK_METAL_HIT, 1.25f, 1.7f); p.setCooldown(p.getInventory().getItemInMainHand().getType(), getCooldownTime(getLevelPercent(p))); damageHand(p, getDamagePerBlock(getLevelPercent(p))); @@ -99,8 +100,8 @@ public void on(PlayerInteractEvent e) { if (getConfig().showParticles) { e.getClickedBlock().getWorld().spawnParticle(Particles.ITEM_CRACK, c, 14, 0.10, 0.01, 0.01, 0.1, is); } - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.25f, 0.787f); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_PLACE, 0.55f, 1.89f); + spw.play(p.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.25f, 0.787f); + spw.play(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_PLACE, 0.55f, 1.89f); e.getClickedBlock().getWorld().dropItemNaturally(c.clone().subtract(p.getLocation().getDirection().clone().multiply(0.1)), is); } else { if (getConfig().showParticles) { @@ -110,8 +111,8 @@ public void on(PlayerInteractEvent e) { } if (M.r(getBreakChance(getLevelPercent(p)))) { - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_BASALT_BREAK, 1.25f, 0.4f); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.25f, 0.887f); + spw.play(p.getLocation(), Sound.BLOCK_BASALT_BREAK, 1.25f, 0.4f); + spw.play(p.getLocation(), Sound.BLOCK_DEEPSLATE_PLACE, 1.25f, 0.887f); e.getClickedBlock().breakNaturally(p.getInventory().getItemInMainHand()); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeDropToInventory.java b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeDropToInventory.java index 7f9af4d7..bee9aee5 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeDropToInventory.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeDropToInventory.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.GameMode; import org.bukkit.Material; @@ -64,6 +65,7 @@ public void on(BlockDropItemEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } @@ -77,7 +79,7 @@ public void on(BlockDropItemEvent e) { List items = e.getItems().copy(); e.getItems().clear(); for (Item i : items) { - p.playSound(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); + sp.play(p.getLocation(), Sound.BLOCK_CALCITE_HIT, 0.05f, 0.01f); if (!p.getInventory().addItem(i.getItemStack()).isEmpty()) { p.getWorld().dropItem(p.getLocation(), i.getItemStack()); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeVeinminer.java b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeVeinminer.java index 43a6f13e..5de524d1 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeVeinminer.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/pickaxe/PickaxeVeinminer.java @@ -20,10 +20,7 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Location; import org.bukkit.Material; @@ -122,7 +119,8 @@ public void on(BlockBreakEvent e) { b.setType(Material.AIR); } else { b.breakNaturally(p.getItemInUse()); - e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.BLOCK_FUNGUS_BREAK, 0.4f, 0.25f); + SoundPlayer spw = SoundPlayer.of(e.getBlock().getWorld()); + spw.play(e.getBlock().getLocation(), Sound.BLOCK_FUNGUS_BREAK, 0.4f, 0.25f); if (getConfig().showParticles) { e.getBlock().getWorld().spawnParticle(Particle.ASH, e.getBlock().getLocation().add(0.5, 0.5, 0.5), 25, 0.5, 0.5, 0.5, 0.1); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedForce.java b/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedForce.java index c7fad332..c1e2c0f0 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedForce.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedForce.java @@ -23,10 +23,7 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.api.advancement.AdaptAdvancement; import com.volmit.adapt.api.advancement.AdvancementVisibility; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Location; import org.bukkit.Material; @@ -97,7 +94,8 @@ public void on(ProjectileLaunchEvent e) { if (hasAdaptation(p)) { double factor = getLevelPercent(p); e.getEntity().setVelocity(e.getEntity().getVelocity().clone().multiply(1 + getSpeed(factor))); - e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENTITY_SNOWBALL_THROW, 0.5f + ((float) factor * 0.25f), 0.7f + (float) (factor / 2f)); + SoundPlayer spw = SoundPlayer.of(e.getEntity().getWorld()); + spw.play(e.getEntity().getLocation(), Sound.ENTITY_SNOWBALL_THROW, 0.5f + ((float) factor * 0.25f), 0.7f + (float) (factor / 2f)); } } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedLungeShot.java b/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedLungeShot.java index f66ee873..887bd984 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedLungeShot.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedLungeShot.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.ranged; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Particle; @@ -72,8 +69,9 @@ public void on(ProjectileLaunchEvent e) { if (!p.isOnGround()) { Vector velocity = p.getPlayer().getLocation().getDirection().normalize().multiply(getSpeed(getLevelPercent(p))); p.setVelocity(p.getVelocity().subtract(velocity)); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_TURTLE, 1f, 0.75f); - p.getWorld().playSound(p.getLocation(), Sound.ITEM_CROSSBOW_SHOOT, 1f, 1.95f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_TURTLE, 1f, 0.75f); + spw.play(p.getLocation(), Sound.ITEM_CROSSBOW_SHOOT, 1f, 1.95f); for (int i = 0; i < 9; i++) { Vector v = velocity.clone().add(Vector.getRandom().subtract(Vector.getRandom()).multiply(0.3)).normalize(); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedWebBomb.java b/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedWebBomb.java index e25cc8ae..c446214e 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedWebBomb.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/ranged/RangedWebBomb.java @@ -23,10 +23,7 @@ import com.volmit.adapt.api.recipe.AdaptRecipe; import com.volmit.adapt.api.recipe.MaterialChar; import com.volmit.adapt.content.item.BoundSnowBall; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import com.volmit.adapt.util.reflect.enums.Particles; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; @@ -152,7 +149,8 @@ public void addWebFoundation(Block block, int seconds) { block.setBlockData(BLOCK); activeBlocks.add(block); }); - block.getWorld().playSound(block.getLocation(), Sound.BLOCK_ROOTED_DIRT_PLACE, 1.0f, 1.0f); + SoundPlayer spw = SoundPlayer.of(block.getWorld()); + spw.play(block.getLocation(), Sound.BLOCK_ROOTED_DIRT_PLACE, 1.0f, 1.0f); if (getConfig().showParticles) { vfxCuboidOutline(block, Particle.CLOUD); @@ -170,7 +168,8 @@ public void removeFoundation(Block block) { block.setBlockData(AIR); activeBlocks.remove(block); }); - block.getWorld().playSound(block.getLocation(), Sound.BLOCK_ROOTED_DIRT_BREAK, 1.0f, 1.0f); + SoundPlayer spw = SoundPlayer.of(block.getWorld()); + spw.play(block.getLocation(), Sound.BLOCK_ROOTED_DIRT_BREAK, 1.0f, 1.0f); if (getConfig().showParticles) { vfxCuboidOutline(block, Particles.ENCHANTMENT_TABLE); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftAccess.java b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftAccess.java index b9d54834..7877facf 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftAccess.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftAccess.java @@ -23,10 +23,7 @@ import com.volmit.adapt.api.adaptation.SimpleAdaptation; import com.volmit.adapt.api.recipe.AdaptRecipe; import com.volmit.adapt.content.item.BoundEnderPearl; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.*; import org.bukkit.block.Block; @@ -144,7 +141,8 @@ private void linkPearl(Player p, Block block, PlayerInteractEvent event) { vfxCuboidOutline(block, Particle.REVERSE_PORTAL); } ItemStack hand = p.getInventory().getItemInMainHand(); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_CLOSE, 0.5f, 0.8f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_CLOSE, 0.5f, 0.8f); if (hand.getAmount() == 1) { BoundEnderPearl.setData(hand, block); @@ -156,9 +154,10 @@ private void linkPearl(Player p, Block block, PlayerInteractEvent event) { } private void openPearl(Player p) { + SoundPlayer sp = SoundPlayer.of(p); Block b = BoundEnderPearl.getBlock(p.getInventory().getItemInMainHand()); if (b == null || !canAccessChest(p, b.getLocation())) { - p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1f, 1f); + sp.play(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1f, 1f); return; } loadChunkAsync(b.getLocation(), chunk -> { @@ -170,8 +169,8 @@ private void openPearl(Player p) { InventoryView view = p.openInventory(holder.getInventory()); activeViewsMap.computeIfAbsent(b.getLocation(), k -> new ArrayList<>()).add(view); } - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); }); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftBlink.java b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftBlink.java index 2461772b..cfb3785f 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftBlink.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftBlink.java @@ -20,7 +20,6 @@ import com.volmit.adapt.Adapt; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.api.world.AdaptPlayer; import com.volmit.adapt.content.event.AdaptAdaptationTeleportEvent; import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; @@ -102,8 +101,9 @@ public void on(PlayerToggleFlightEvent e) { while (!isSafe(loc) && cd-- > 0) { loc.add(0, 1, 0); } + SoundPlayer spw = SoundPlayer.of(p.getWorld()); if (!isSafe(loc)) { - p.getWorld().playSound(p.getLocation(), Sound.BLOCK_CONDUIT_DEACTIVATE, 1f, 1.24f); + spw.play(p.getLocation(), Sound.BLOCK_CONDUIT_DEACTIVATE, 1f, 1.24f); lastJump.put(p, M.ms()); return; } @@ -129,7 +129,7 @@ public void on(PlayerToggleFlightEvent e) { J.s(() -> p.setVelocity(v.multiply(3)), 2); }); lastJump.put(p, M.ms()); - p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 0.50f, 1.0f); + spw.play(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 0.50f, 1.0f); vfxLevelUp(p); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftDescent.java b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftDescent.java index 4e30d4c6..d17a549d 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftDescent.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftDescent.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.rift; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -61,6 +58,7 @@ public void addStats(int level, Element v) { @EventHandler(priority = EventPriority.HIGHEST) public void on(PlayerToggleSneakEvent e) { Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (p.getPotionEffect(PotionEffectType.LEVITATION) == null) { return; } @@ -82,14 +80,14 @@ public void on(PlayerToggleSneakEvent e) { } catch (InterruptedException ex) { throw new RuntimeException(ex); } - p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f); + sp.play(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f); cooldown.remove(p); }); J.s(() -> { p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, (int) (20 * getConfig().cooldown), 0)); - p.playSound(p.getLocation(), Sound.ENTITY_ENDER_DRAGON_FLAP, 1f, 1f); + sp.play(p.getLocation(), Sound.ENTITY_ENDER_DRAGON_FLAP, 1f, 1f); }); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftEnderchest.java b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftEnderchest.java index 538b2419..e58e3950 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftEnderchest.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftEnderchest.java @@ -22,6 +22,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -54,6 +55,7 @@ public void addStats(int level, Element v) { @EventHandler public void on(PlayerInteractEvent e) { Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); ItemStack hand = p.getInventory().getItemInMainHand(); if (hand.getType() != Material.ENDER_CHEST || !hasAdaptation(p)) { @@ -70,8 +72,8 @@ public void on(PlayerInteractEvent e) { && getPlayer(p).getData().getSkillLines().get("rift").getAdaptations().get("rift-resist").getLevel() > 0) { RiftResist.riftResistStackAdd(p, 10, 2); } - p.playSound(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); + sp.play(p.getLocation(), Sound.PARTICLE_SOUL_ESCAPE, 1f, 0.10f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1f, 0.10f); p.openInventory(p.getEnderChest()); } } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftGate.java b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftGate.java index 693e7f48..7af1a37f 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftGate.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftGate.java @@ -23,10 +23,7 @@ import com.volmit.adapt.api.recipe.AdaptRecipe; import com.volmit.adapt.content.event.AdaptAdaptationTeleportEvent; import com.volmit.adapt.content.item.BoundEyeOfEnder; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.*; import org.bukkit.block.Block; @@ -147,7 +144,8 @@ private void linkEye(Player p, Location location) { if (getConfig().showParticles) { vfxCuboidOutline(location.getBlock(), location.add(0, 1, 0).getBlock(), Particle.REVERSE_PORTAL); } - p.playSound(p.getLocation(), Sound.ENTITY_ENDER_EYE_DEATH, 0.50f, 0.22f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.ENTITY_ENDER_EYE_DEATH, 0.50f, 0.22f); ItemStack hand = p.getInventory().getItemInMainHand(); if (hand.getAmount() == 1) { @@ -162,6 +160,7 @@ private void linkEye(Player p, Location location) { private void openEye(Player p) { Adapt.verbose("Using eye"); + SoundPlayer sp = SoundPlayer.of(p); Location l = BoundEyeOfEnder.getLocation(p.getInventory().getItemInMainHand()); ItemStack hand = p.getInventory().getItemInMainHand(); @@ -170,7 +169,7 @@ private void openEye(Player p) { decrementItemstack(hand, p); } else { if (p.getCooldown(Material.ENDER_EYE) > 0) { - p.playSound(p.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 1, 1); + sp.play(p.getLocation(), Sound.BLOCK_REDSTONE_TORCH_BURNOUT, 1, 1); return; } } @@ -183,8 +182,8 @@ private void openEye(Player p) { p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 10, true, false, false)); p.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 85, 0, true, false, false)); - p.playSound(l, Sound.BLOCK_LODESTONE_PLACE, 1f, 0.1f); - p.playSound(l, Sound.BLOCK_BELL_RESONATE, 1f, 0.1f); + sp.play(l, Sound.BLOCK_LODESTONE_PLACE, 1f, 0.1f); + sp.play(l, Sound.BLOCK_BELL_RESONATE, 1f, 0.1f); J.a(() -> { long dur = 4000; // time in miliseconds @@ -201,7 +200,7 @@ private void openEye(Player p) { } }); vfxLevelUp(p); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 5.35f, 0.1f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 5.35f, 0.1f); J.s(() -> { AdaptAdaptationTeleportEvent event = new AdaptAdaptationTeleportEvent(!Bukkit.isPrimaryThread(), getPlayer(p), this, p.getLocation(), l); Bukkit.getPluginManager().callEvent(event); @@ -211,7 +210,7 @@ private void openEye(Player p) { p.teleport(l, PlayerTeleportEvent.TeleportCause.PLUGIN); vfxLevelUp(p); - p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 5.35f, 0.1f); + sp.play(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 5.35f, 0.1f); }, 85); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftResist.java b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftResist.java index a9a66d5e..8a730bcf 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftResist.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/rift/RiftResist.java @@ -23,6 +23,7 @@ import com.volmit.adapt.util.C; import com.volmit.adapt.util.Element; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import com.volmit.adapt.util.reflect.enums.PotionEffectTypes; import lombok.NoArgsConstructor; import org.bukkit.Material; @@ -54,9 +55,10 @@ static void riftResistStackAdd(Player p, int duration, int amplifier) { if (p.getLocation().getWorld() == null) { return; } - p.getWorld().playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_IRON, 1f, 1.24f); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_CONDUIT_AMBIENT_SHORT, 1f, 0.01f); - p.getLocation().getWorld().playSound(p.getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1f, 0.01f); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); + spw.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_IRON, 1f, 1.24f); + spw.play(p.getLocation(), Sound.BLOCK_CONDUIT_AMBIENT_SHORT, 1f, 0.01f); + spw.play(p.getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1f, 0.01f); p.addPotionEffect(new PotionEffect(PotionEffectTypes.DAMAGE_RESISTANCE, duration, amplifier, true, false, false)); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSight.java b/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSight.java index 3de93d01..14255002 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSight.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSight.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.stealth; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Sound; @@ -65,12 +62,13 @@ public void on(PlayerToggleSneakEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); if (!hasAdaptation(p)) { return; } sneaking.add(p); if (!p.isSneaking()) { - p.playSound(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 1, 0.99f); + sp.play(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 1, 0.99f); p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000, 0, false, false)); } else { p.removePotionEffect(PotionEffectType.NIGHT_VISION); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSnatch.java b/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSnatch.java index b961422c..f6a080ec 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSnatch.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSnatch.java @@ -99,7 +99,8 @@ private void snatch(Player player) { if (Inventories.hasSpace(player.getInventory(), is)) { holds.add(droppedItemEntity.getEntityId()); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LAVA_POP, 1f, (float) (1.0 + (Math.random() / 3))); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); + spw.play(player.getLocation(), Sound.BLOCK_LAVA_POP, 1f, (float) (1.0 + (Math.random() / 3))); safeGiveItem(player, droppedItemEntity, is); //sendCollected(player, droppedItemEntity); int id = droppedItemEntity.getEntityId(); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSpeed.java b/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSpeed.java index 10be01e1..99582548 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSpeed.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/stealth/StealthSpeed.java @@ -61,6 +61,7 @@ public void on(PlayerToggleSneakEvent e) { return; } Player p = e.getPlayer(); + SoundPlayer sp = SoundPlayer.of(p); double factor = getLevelPercent(p); if (!hasAdaptation(p)) { return; @@ -72,7 +73,7 @@ public void on(PlayerToggleSneakEvent e) { sneaking.add(p); if (!p.isSneaking()) { - p.playSound(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 1, 0.99f); + sp.play(p.getLocation(), Sound.BLOCK_FUNGUS_BREAK, 1, 0.99f); p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000, getLevel(p), false, false)); } else { p.removePotionEffect(PotionEffectType.SPEED); diff --git a/src/main/java/com/volmit/adapt/content/adaptation/sword/SwordsMachete.java b/src/main/java/com/volmit/adapt/content/adaptation/sword/SwordsMachete.java index 1ee24431..26ca7b2b 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/sword/SwordsMachete.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/sword/SwordsMachete.java @@ -68,6 +68,7 @@ public double getRadius(int level) { @EventHandler public void on(PlayerInteractEvent e) { Player p = e.getPlayer(); + SoundPlayer spw = SoundPlayer.of(p.getWorld()); if (e.getHand() != null && e.getHand().equals(EquipmentSlot.HAND) && e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) { int dmg = 0; ItemStack is = e.getItem(); @@ -141,7 +142,7 @@ public void on(PlayerInteractEvent e) { dmg += 1; J.s(() -> { i.breakNaturally(); - p.getWorld().playSound(i.getLocation(), Sound.BLOCK_GRASS_BREAK, 0.4f, (float) Math.random() * 1.85f); + spw.play(i.getLocation(), Sound.BLOCK_GRASS_BREAK, 0.4f, (float) Math.random() * 1.85f); }, RNG.r.i(0, (getMaxLevel() - lvl * 2) + 1)); } } @@ -153,7 +154,7 @@ public void on(PlayerInteractEvent e) { // if (getConfig().showParticles) { // ParticleEffect.SWEEP_ATTACK.display(p.getEyeLocation().clone().add(p.getLocation().getDirection().clone().multiply(1.25)).add(0, -0.5, 0), 0f, 0f, 0f, 0.1f, 1, null); // } - p.getWorld().playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_ATTACK_SWEEP, 1f, (float) (Math.random() / 2) + 0.65f); + spw.play(p.getEyeLocation(), Sound.ENTITY_PLAYER_ATTACK_SWEEP, 1f, (float) (Math.random() / 2) + 0.65f); damageHand(p, dmg * getDamagePerBlock(getLevelPercent(lvl))); getSkill().xp(p, dmg * 11.25); } diff --git a/src/main/java/com/volmit/adapt/content/adaptation/unarmed/UnarmedSuckerPunch.java b/src/main/java/com/volmit/adapt/content/adaptation/unarmed/UnarmedSuckerPunch.java index c628f0fc..b67642c1 100644 --- a/src/main/java/com/volmit/adapt/content/adaptation/unarmed/UnarmedSuckerPunch.java +++ b/src/main/java/com/volmit/adapt/content/adaptation/unarmed/UnarmedSuckerPunch.java @@ -19,10 +19,7 @@ package com.volmit.adapt.content.adaptation.unarmed; import com.volmit.adapt.api.adaptation.SimpleAdaptation; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.Element; -import com.volmit.adapt.util.Form; -import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.*; import lombok.NoArgsConstructor; import org.bukkit.Material; import org.bukkit.Particle; @@ -85,8 +82,9 @@ public void on(EntityDamageByEntityEvent e) { } e.setDamage(e.getDamage() * getDamage(factor)); - e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.ENTITY_PLAYER_ATTACK_STRONG, 1f, 1.8f); - e.getEntity().getWorld().playSound(e.getEntity().getLocation(), Sound.BLOCK_BASALT_BREAK, 1f, 0.6f); + SoundPlayer spw = SoundPlayer.of(e.getEntity().getWorld()); + spw.play(e.getEntity().getLocation(), Sound.ENTITY_PLAYER_ATTACK_STRONG, 1f, 1.8f); + spw.play(e.getEntity().getLocation(), Sound.BLOCK_BASALT_BREAK, 1f, 0.6f); getSkill().xp(p, 6.221 * e.getDamage()); if (e.getDamage() > 5) { getSkill().xp(p, 0.42 * e.getDamage()); diff --git a/src/main/java/com/volmit/adapt/content/gui/SkillsGui.java b/src/main/java/com/volmit/adapt/content/gui/SkillsGui.java index 221e6e6c..dc450986 100644 --- a/src/main/java/com/volmit/adapt/content/gui/SkillsGui.java +++ b/src/main/java/com/volmit/adapt/content/gui/SkillsGui.java @@ -86,8 +86,9 @@ public static void open(Player player) { : "")) .onLeftClick((e) -> { Adapt.instance.getAdaptServer().getSkillRegistry().getSkills().forEach(skill -> skill.getAdaptations().forEach(adaptation -> adaptation.unlearn(player, 1, false))); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_NETHER_GOLD_ORE_PLACE, 0.7f, 1.355f); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.4f, 0.755f); + SoundPlayer spw = SoundPlayer.of(player.getWorld()); + spw.play(player.getLocation(), Sound.BLOCK_NETHER_GOLD_ORE_PLACE, 0.7f, 1.355f); + spw.play(player.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.4f, 0.755f); w.close(); if (AdaptConfig.get().getLearnUnlearnButtonDelayTicks() != 0) { player.sendTitle(" ", C.GRAY + Localizer.dLocalize("snippets", "gui", "unlearnedall"), 1, 5, 11); diff --git a/src/main/java/com/volmit/adapt/content/skill/SkillBlocking.java b/src/main/java/com/volmit/adapt/content/skill/SkillBlocking.java index 040a34af..61b09539 100644 --- a/src/main/java/com/volmit/adapt/content/skill/SkillBlocking.java +++ b/src/main/java/com/volmit/adapt/content/skill/SkillBlocking.java @@ -30,6 +30,7 @@ import com.volmit.adapt.content.adaptation.blocking.BlockingSaddlecrafter; import com.volmit.adapt.util.C; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -115,6 +116,7 @@ public void on(EntityDamageByEntityEvent e) { return; } if (e.getEntity() instanceof Player p) { + SoundPlayer sp = SoundPlayer.of(p); shouldReturnForPlayer(p, e, () -> { if (p.isBlocking()) { AdaptPlayer adaptPlayer = getPlayer(p); @@ -123,8 +125,8 @@ public void on(EntityDamageByEntityEvent e) { handleCooldown(p, () -> { xp(p, getConfig().xpOnBlockedAttack); - p.playSound(p.getLocation(), Sound.BLOCK_IRON_DOOR_CLOSE, 0.5f, 0.77f); - p.playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 0.5f, 0.77f); + sp.play(p.getLocation(), Sound.BLOCK_IRON_DOOR_CLOSE, 0.5f, 0.77f); + sp.play(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_LEATHER, 0.5f, 0.77f); }); } }); diff --git a/src/main/java/com/volmit/adapt/content/skill/SkillTragOul.java b/src/main/java/com/volmit/adapt/content/skill/SkillTragOul.java index c66d0ab6..529870e8 100644 --- a/src/main/java/com/volmit/adapt/content/skill/SkillTragOul.java +++ b/src/main/java/com/volmit/adapt/content/skill/SkillTragOul.java @@ -30,6 +30,7 @@ import com.volmit.adapt.content.adaptation.tragoul.TragoulThorns; import com.volmit.adapt.util.C; import com.volmit.adapt.util.Localizer; +import com.volmit.adapt.util.SoundPlayer; import com.volmit.adapt.util.reflect.enums.Particles; import de.slikey.effectlib.effect.CloudEffect; import lombok.NoArgsConstructor; @@ -117,7 +118,8 @@ public void on(PlayerDeathEvent e) { return; } - p.playSound(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1f, 1f); + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.ENTITY_BLAZE_DEATH, 1f, 1f); PlayerSkillLine tragoul = a.getData().getSkillLines().get("tragoul"); if (tragoul != null) { diff --git a/src/main/java/com/volmit/adapt/util/MortarCommand.java b/src/main/java/com/volmit/adapt/util/MortarCommand.java index 24e5ac66..9a764b66 100644 --- a/src/main/java/com/volmit/adapt/util/MortarCommand.java +++ b/src/main/java/com/volmit/adapt/util/MortarCommand.java @@ -71,7 +71,8 @@ public List handleTab(MortarSender sender, String[] args) { } if (sender.isPlayer()) { - sender.player().getWorld().playSound(sender.player().getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 0.25f, 1.7f); + SoundPlayer spw = SoundPlayer.of(sender.player().getWorld()); + spw.play(sender.player().getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 0.25f, 1.7f); } return v; @@ -99,8 +100,9 @@ public void printHelp(MortarSender sender) { } if (sender.isPlayer()) { - sender.player().getWorld().playSound(sender.player().getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.28f, 1.4f); - sender.player().getWorld().playSound(sender.player().getLocation(), Sound.ITEM_AXE_STRIP, 0.35f, 1.7f); + SoundPlayer spw = SoundPlayer.of(sender.player().getWorld()); + spw.play(sender.player().getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.28f, 1.4f); + spw.play(sender.player().getLocation(), Sound.ITEM_AXE_STRIP, 0.35f, 1.7f); } } diff --git a/src/main/java/com/volmit/adapt/util/SoundPlayer.java b/src/main/java/com/volmit/adapt/util/SoundPlayer.java new file mode 100644 index 00000000..79596d22 --- /dev/null +++ b/src/main/java/com/volmit/adapt/util/SoundPlayer.java @@ -0,0 +1,51 @@ +package com.volmit.adapt.util; + +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.List; + +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class SoundPlayer { + + private final Collection players; + + public static SoundPlayer of(Collection players) { + return new SoundPlayer(players); + } + + public static SoundPlayer of(Player player) { + return new SoundPlayer(List.of(player)); + } + + public static SoundPlayer of(World world) { + return new SoundPlayer(world.getPlayers()); + } + + public void play(@NotNull Location location, @NotNull Sound sound) { + play(location, sound, 1.0f, 1.0f); + } + + public void play(@NotNull Entity entity, @NotNull Sound sound, float volume, float pitch) { + play(entity.getLocation(), sound, volume, pitch); + } + + public void play(@NotNull Location location, @NotNull Sound sound, float volume, float pitch) { + players.forEach(player -> player.playSound(location, sound, volume, pitch)); + //J.s(() -> Objects.requireNonNull(location.getWorld()).playSound(location, sound, volume, pitch)); + } + + public void play(@NotNull Location location, @NotNull Sound sound, SoundCategory category, float volume, float pitch) { + players.forEach(player -> player.playSound(location, sound, category, volume, pitch)); + //J.s(() -> Objects.requireNonNull(location.getWorld()).playSound(location, sound, volume, pitch)); + } + +} diff --git a/src/main/java/com/volmit/adapt/util/VirtualCommand.java b/src/main/java/com/volmit/adapt/util/VirtualCommand.java index b5d72720..741dfb04 100644 --- a/src/main/java/com/volmit/adapt/util/VirtualCommand.java +++ b/src/main/java/com/volmit/adapt/util/VirtualCommand.java @@ -107,7 +107,8 @@ public boolean hit(CommandSender sender, List chain, String label) { c.remove(0); if (cmd.hit(sender, c, vs.getCommand())) { if (vs.isPlayer()) { - vs.player().getWorld().playSound(vs.player().getLocation(), Sound.ITEM_AXE_STRIP, 0.35f, 1.8f); + SoundPlayer spw = SoundPlayer.of(vs.player().getWorld()); + spw.play(vs.player().getLocation(), Sound.ITEM_AXE_STRIP, 0.35f, 1.8f); } return true; diff --git a/src/main/java/com/volmit/adapt/util/decree/DecreeSystem.java b/src/main/java/com/volmit/adapt/util/decree/DecreeSystem.java index 6e15817d..16a9ec84 100644 --- a/src/main/java/com/volmit/adapt/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/adapt/util/decree/DecreeSystem.java @@ -20,10 +20,7 @@ package com.volmit.adapt.util.decree; import com.volmit.adapt.Adapt; -import com.volmit.adapt.util.C; -import com.volmit.adapt.util.J; -import com.volmit.adapt.util.RNG; -import com.volmit.adapt.util.VolmitSender; +import com.volmit.adapt.util.*; import com.volmit.adapt.util.collection.KList; import com.volmit.adapt.util.decree.virtual.VirtualDecreeCommand; import org.bukkit.Sound; @@ -145,8 +142,9 @@ default List onTabComplete(@NotNull CommandSender sender, @NotNull Comma KList v = getRoot().tabComplete(enhanced, enhanced.toString(" ")); v.removeDuplicates(); - if (sender instanceof Player) { - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f)); + if (sender instanceof Player p) { + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f)); } return v; @@ -161,16 +159,18 @@ default boolean onCommand(@NotNull CommandSender sender, @NotNull Command comman J.a(() -> { if (!call(new VolmitSender(sender), args)) { - if (sender instanceof Player) { - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, 0.77f, 0.25f); - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f); + if (sender instanceof Player p) { + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, 0.77f, 0.25f); + sp.play(p.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f); } sender.sendMessage(C.RED + "Unknown Adapt Command"); } else { - if (sender instanceof Player) { - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 1.65f); - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.125f, 2.99f); + if (sender instanceof Player p) { + SoundPlayer sp = SoundPlayer.of(p); + sp.play(p.getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 1.65f); + sp.play(p.getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.125f, 2.99f); } } });