Skip to content

Commit

Permalink
Merge pull request #504 from IPECTER/Development
Browse files Browse the repository at this point in the history
Add SoundPlayer for playSound issue
  • Loading branch information
NextdoorPsycho authored Sep 5, 2024
2 parents 68f22d1 + 4532bd5 commit 60a48b9
Show file tree
Hide file tree
Showing 62 changed files with 385 additions and 293 deletions.
13 changes: 8 additions & 5 deletions src/main/java/com/volmit/adapt/api/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -213,7 +214,7 @@ default boolean isAdaptableDamageCause(EntityDamageEvent event) {

default void addPotionStacks(Player p, PotionEffectType potionEffect, int amplifier, int duration, boolean overlap) {
List<PotionEffect> activeEffects = new ArrayList<>(p.getActivePotionEffects());

SoundPlayer sp = SoundPlayer.of(p);
for (PotionEffect activeEffect : activeEffects) {
if (activeEffect.getType() == potionEffect) {
if (!overlap) {
Expand All @@ -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;
}
}
Expand All @@ -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);
});
});

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
37 changes: 19 additions & 18 deletions src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand All @@ -456,24 +456,24 @@ 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) {
player.sendTitle(" ", C.GRAY + Localizer.dLocalize("snippets", "adaptmenu", "learned") + " " + getDisplayName(lvl), 1, 5, 11);
}
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(" ");
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/volmit/adapt/api/potion/BrewingTask.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/volmit/adapt/api/skill/Skill.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/volmit/adapt/api/skill/SkillRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/volmit/adapt/api/world/AdaptServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/volmit/adapt/command/CommandDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Loading

0 comments on commit 60a48b9

Please sign in to comment.