Skip to content

Commit

Permalink
remove SoundHelper entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 14, 2022
1 parent f1910c2 commit 5f512b4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 89 deletions.
Expand Up @@ -895,7 +895,7 @@ public static void registerTags() {
// @returns ElementTag(Decimal)
// @mechanism PlayerTag.health_scale
// @description
// Returns the current scale for the player's health bar
// Returns the current scale for the player's health bar.
// -->
registerOfflineTag(ElementTag.class, "health_scale", (attribute, object) -> {
return new ElementTag(object.getPlayerEntity().getHealthScale());
Expand Down
@@ -1,7 +1,6 @@
package com.denizenscript.denizen.scripts.commands.world;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.midi.SoundHelper;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.Utilities;
Expand All @@ -13,6 +12,7 @@
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.Player;

import java.util.Collections;
Expand Down Expand Up @@ -134,7 +134,7 @@ public void execute(ScriptEntry scriptEntry) {
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
SoundHelper.playSound(ent, location, Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
player.getPlayerEntity().playSound(location, Sound.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 1, 1);
}
NMSHandler.packetHelper.showBlockAction(ent, location, 1, 1);
}
Expand All @@ -143,7 +143,7 @@ public void execute(ScriptEntry scriptEntry) {
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
SoundHelper.playSound(ent, location, Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
player.getPlayerEntity().playSound(location, Sound.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 1, 1);
}
NMSHandler.packetHelper.showBlockAction(ent, location, 1, 0);
}
Expand Down
@@ -1,6 +1,5 @@
package com.denizenscript.denizen.scripts.commands.world;

import com.denizenscript.denizen.utilities.midi.SoundHelper;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
Expand All @@ -12,6 +11,7 @@
import com.denizenscript.denizencore.utilities.CoreConfiguration;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;

import java.util.List;

Expand Down Expand Up @@ -118,38 +118,42 @@ public void execute(ScriptEntry scriptEntry) {
float volume = volumeElement.asFloat();
float pitch = pitchElement.asFloat();
String category = sound_category.asString().toUpperCase();
SoundCategory categoryEnum = category != null ? new ElementTag(category).asEnum(SoundCategory.class) : null;
if (categoryEnum == null) {
categoryEnum = SoundCategory.MASTER;
}
try {
if (players == null) {
if (custom) {
for (LocationTag location : locations) {
SoundHelper.playSound(null, location, sound, volume, pitch, category);
location.getWorld().playSound(location, sound, categoryEnum, volume, pitch);
}
}
else {
for (LocationTag location : locations) {
SoundHelper.playSound(null, location, Sound.valueOf(sound.toUpperCase()), volume, pitch, category);
location.getWorld().playSound(location, Sound.valueOf(sound.toUpperCase()), categoryEnum, volume, pitch);
}
}
}
else if (locations != null) {
for (LocationTag location : locations) {
for (PlayerTag player : players) {
if (custom) {
SoundHelper.playSound(player.getPlayerEntity(), location, sound, volume, pitch, category);
player.getPlayerEntity().playSound(location, sound, categoryEnum, volume, pitch);
}
else {
SoundHelper.playSound(player.getPlayerEntity(), location, Sound.valueOf(sound.toUpperCase()), volume, pitch, category);
player.getPlayerEntity().playSound(location, Sound.valueOf(sound.toUpperCase()), categoryEnum, volume, pitch);
}
}
}
}
else {
for (PlayerTag player : players) {
if (custom) {
SoundHelper.playSound(player.getPlayerEntity(), player.getLocation(), sound, volume, pitch, category);
player.getPlayerEntity().playSound(player.getLocation(), sound, categoryEnum, volume, pitch);
}
else {
SoundHelper.playSound(player.getPlayerEntity(), player.getLocation(), Sound.valueOf(sound.toUpperCase()), volume, pitch, category);
player.getPlayerEntity().playSound(player.getPlayerEntity(), Sound.valueOf(sound.toUpperCase()), categoryEnum, volume, pitch);
}
}
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.Maps;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;

import javax.sound.midi.*;
import java.util.List;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void playNote(ShortMessage message) {
// get pitch and volume from the midi message
float pitch = (float) ToneUtil.midiToPitch(message);
float volume = VOLUME_RANGE * (message.getData2() / 127.0f);
Sound instrument = patch == null ? SoundHelper.defaultMidiInstrument : SoundHelper.getMidiInstrumentFromPatch(patch);
Sound instrument = patch == null ? defaultMidiInstrument : getMidiInstrumentFromPatch(patch);
Runnable actualPlay = () -> {
if (location != null) {
location.getWorld().playSound(location, instrument, volume, pitch);
Expand All @@ -106,10 +107,10 @@ else if (entities != null && !entities.isEmpty()) {
EntityTag entity = entities.get(i);
if (entity.isSpawned()) {
if (entity.isPlayer()) {
SoundHelper.playSound(entity.getPlayer(), entity.getLocation(), instrument, volume, pitch, "RECORDS");
entity.getPlayer().playSound(entity.getPlayer(), instrument, SoundCategory.RECORDS, volume, pitch);
}
else {
SoundHelper.playSound(null, entity.getLocation(), instrument, volume, pitch, "RECORDS");
entity.getLocation().getWorld().playSound(entity.getLocation(), instrument, SoundCategory.RECORDS, volume, pitch);
}
}
else {
Expand Down Expand Up @@ -158,4 +159,42 @@ public void close() {
}
}, 1);
}

private static final int[] instruments_1_12 = {
0, 0, 0, 0, 0, 0, 0, 5, // 8
9, 9, 9, 9, 9, 6, 0, 9, // 16
9, 0, 0, 0, 0, 0, 0, 5, // 24
5, 5, 5, 5, 5, 5, 5, 1, // 32
1, 1, 1, 1, 1, 1, 1, 5, // 40
1, 5, 5, 5, 5, 5, 5, 5, // 48
5, 5, 5, 8, 8, 8, 8, 8, // 56
8, 8, 8, 8, 8, 8, 8, 8, // 64
8, 8, 8, 8, 8, 8, 8, 8, // 72
8, 8, 8, 8, 8, 8, 8, 8, // 80
0, 0, 0, 0, 0, 0, 0, 0, // 88
0, 0, 0, 0, 0, 0, 0, 0, // 96
0, 0, 0, 0, 0, 0, 0, 5, // 104
5, 5, 5, 9, 8, 5, 8, 6, // 112
6, 3, 3, 2, 2, 2, 6, 5, // 120
1, 1, 1, 6, 1, 2, 4, 7, // 128
};

public static Sound getMidiInstrumentFromPatch(int patch) {
switch (instruments_1_12[patch]) {
case 0: return Sound.BLOCK_NOTE_BLOCK_HARP;
case 1: return Sound.BLOCK_NOTE_BLOCK_BASS;
case 2: return Sound.BLOCK_NOTE_BLOCK_SNARE;
case 3: return Sound.BLOCK_NOTE_BLOCK_HAT;
case 4: return Sound.BLOCK_NOTE_BLOCK_BASEDRUM;
case 5: return Sound.BLOCK_NOTE_BLOCK_GUITAR;
case 6: return Sound.BLOCK_NOTE_BLOCK_BELL;
case 7: return Sound.BLOCK_NOTE_BLOCK_CHIME;
case 8: return Sound.BLOCK_NOTE_BLOCK_FLUTE;
case 9: return Sound.BLOCK_NOTE_BLOCK_XYLOPHONE;
case 10: return Sound.BLOCK_NOTE_BLOCK_PLING;
default: return defaultMidiInstrument;
}
}

public static final Sound defaultMidiInstrument = Sound.BLOCK_NOTE_BLOCK_HARP;
}

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -32,7 +32,7 @@
<repositories>
<repository>
<id>everything</id>
<url>https://maven.citizensnpcs.co</url>
<url>https://maven.citizensnpcs.co/repo</url>
</repository>
<!--<repository>
<id>spigot-repo</id>
Expand Down

0 comments on commit 5f512b4

Please sign in to comment.