Skip to content

Commit

Permalink
Minimum start for sound keys
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 committed Sep 15, 2024
1 parent 50c2bc3 commit 0443673
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.google.gson.JsonObject;
import java.nio.file.Path;
import java.util.List;
import net.kyori.adventure.key.Key;
import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
Expand Down Expand Up @@ -102,4 +104,9 @@ public int getWorldDataVersion(Path levelDat) {
return -1;
}
}

@Override
public Key getSound(Sound enumConstant) {
return enumConstant.key();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package tc.oc.pgm.platform.sportpaper;

import static net.kyori.adventure.key.Key.key;
import static tc.oc.pgm.util.platform.Supports.Priority.HIGH;
import static tc.oc.pgm.util.platform.Supports.Variant.SPORTPAPER;

import com.google.gson.JsonObject;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import net.kyori.adventure.key.Key;
import net.minecraft.server.v1_8_R3.EntityPotion;
import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftSound;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Arrow;
Expand Down Expand Up @@ -101,4 +105,10 @@ public int getWorldDataVersion(Path levelDat) {
return -1;
}
}

@Override
@SuppressWarnings("PatternValidation")
public Key getSound(Sound enumConstant) {
return key(CraftSound.getSound(enumConstant));
}
}
14 changes: 5 additions & 9 deletions util/src/main/java/tc/oc/pgm/util/Audience.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tc.oc.pgm.util;

import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.sound.Sound.sound;
import static net.kyori.adventure.text.Component.text;

import java.util.ArrayList;
Expand All @@ -12,31 +10,29 @@
import java.util.stream.Collectors;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import tc.oc.pgm.util.bukkit.BukkitUtils;
import tc.oc.pgm.util.bukkit.Sounds;
import tc.oc.pgm.util.text.ComponentRenderer;

/** Receiver of chat messages, sounds, titles, and other media. */
@FunctionalInterface
public interface Audience extends ForwardingAudience.Single {

Sound WARNING_SOUND = sound(key("note.bass"), Sound.Source.MASTER, 1f, 0.75f);
Component WARNING_MESSAGE = text(" \u26a0 ", NamedTextColor.YELLOW); // ⚠

default void sendWarning(ComponentLike message) {
sendMessage(WARNING_MESSAGE.append(message.asComponent().colorIfAbsent(NamedTextColor.RED)));
playSound(WARNING_SOUND);
playSound(Sounds.WARNING);
}

BukkitAudiences PROVIDER =
BukkitAudiences.builder(BukkitUtils.getPlugin())
.componentRenderer(ComponentRenderer.RENDERER)
.build();
BukkitAudiences PROVIDER = BukkitAudiences.builder(BukkitUtils.getPlugin())
.componentRenderer(ComponentRenderer.RENDERER)
.build();

static Audience console() {
return PROVIDER::console;
Expand Down
4 changes: 4 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/bukkit/MiscUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.google.gson.JsonObject;
import java.nio.file.Path;
import java.util.List;
import net.kyori.adventure.key.Key;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -51,4 +53,6 @@ EntityChangeBlockEvent createEntityChangeBlockEvent(
double getArrowDamage(Arrow arrow);

int getWorldDataVersion(Path levelDat);

Key getSound(Sound constant);
}
19 changes: 19 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/bukkit/Sounds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tc.oc.pgm.util.bukkit;

import static net.kyori.adventure.sound.Sound.sound;
import static tc.oc.pgm.util.bukkit.MiscUtils.MISC_UTILS;

import net.kyori.adventure.sound.Sound;

public interface Sounds {
Sound WARNING = sound("NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS", 1f, 0.75f);

static Sound sound(String legacyConstant, String modernConstant, float volume, float pitch) {
return sound(
MISC_UTILS.getSound(
BukkitUtils.parse(org.bukkit.Sound::valueOf, legacyConstant, modernConstant)),
Sound.Source.MASTER,
volume,
pitch);
}
}

0 comments on commit 0443673

Please sign in to comment.