Skip to content

Commit

Permalink
音再生
Browse files Browse the repository at this point in the history
  • Loading branch information
aburaagetarou committed Jan 25, 2025
1 parent a4be1dd commit febeebb
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 53 deletions.
133 changes: 132 additions & 1 deletion src/main/java/com/github/aburaagearou/yatchayatcha/YYConfigUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.github.aburaagearou.yatchayatcha;

import java.util.List;
import org.bukkit.Sound;

import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
* 設定ファイルユーティリティクラス
Expand All @@ -14,6 +19,32 @@ public class YYConfigUtil {
public static final String BID_MIN_PRICE_AD = "bid-min-price-add";
public static final String LUNACHAT_AUCTION_CHANNEL = "lc-auction-channel";

// 効果音設定
public static final String SOUND_EFFECTS = "sound-effects";
public static final String SE_START = "start";
public static final String SE_BID_SELF = "bid-self";
public static final String SE_BID_RIVAL = "bid-rival";
public static final String SE_COUNTDOWN = "countdown";
public static final String SE_SUCCESS = "success";

// 効果音リスト
private static final Map<String, Sound> sounds = new HashMap<>();
static {
Arrays.stream(Sound.values()).forEach(sound -> sounds.put(sound.name().replace(".", "_"), sound));
}

// 効果音設定
private static final Map<String, List<SoundSetting>> soundSettings = new HashMap<>();

/**
* 再読み込み
*/
public static void reload() {
YatchaYatcha.getInstance().saveDefaultConfig();
YatchaYatcha.getInstance().reloadConfig();
soundSettings.clear();
}

/**
* カウントダウン秒数を取得
* @return 秒数(int)
Expand Down Expand Up @@ -53,4 +84,104 @@ public static int getBidMinPriceAdd() {
public static String getLunaChatAuctionChannel() {
return YatchaYatcha.getInstance().getConfig().getString(LUNACHAT_AUCTION_CHANNEL);
}

/**
* 効果音設定を取得
* @param seKey sound-effects配下のキー名
* @return 効果音設定リスト
*/
@Nullable
public static List<SoundSetting> getSoundSetting(String seKey) {
String key = SOUND_EFFECTS + "." + seKey;
if(!soundSettings.containsKey(seKey)) {
if(!YatchaYatcha.getInstance().getConfig().isString(key)) {
return null;
}
List<SoundSetting> settings = Arrays.stream(YatchaYatcha.getInstance().getConfig().getString(key).split(","))
.map(YYConfigUtil::parseSoundSetting)
.filter(Objects::nonNull)
.collect(Collectors.toList());
soundSettings.put(seKey, settings);
}
return soundSettings.get(seKey);
}

/**
* 効果音設定の分解
* @param key 設定キー("SOUND_NAME-VOLUME-PITCH(-DELAY)")
*/
@Nullable
public static SoundSetting parseSoundSetting(String key) {
// 設定の分解("SOUND_NAME-VOLUME-PITCH(-DELAY)")
String[] soundSetting = key.split("-");
if(soundSetting.length < 3) {
return null;
}

// 効果音の取得
Sound sound = sounds.get(soundSetting[0].toUpperCase());
if(sound == null) return null;
BigDecimal volume = new BigDecimal(soundSetting[1]);
BigDecimal pitch = new BigDecimal(soundSetting[2]);
BigDecimal delay = new BigDecimal(0);
if(soundSetting.length >= 4) {
delay = new BigDecimal(soundSetting[3]);
}
return new SoundSetting(sound, volume.floatValue(), pitch.floatValue(), delay.intValue());
}

/**
* 効果音設定
*/
public static class SoundSetting {
private final Sound sound;
private final float volume;
private final float pitch;
private final int delay;

/**
* コンストラクタ
* @param sound 効果音
* @param volume 音量
* @param pitch ピッチ
*/
public SoundSetting(Sound sound, float volume, float pitch, int delay) {
this.sound = sound;
this.volume = volume;
this.pitch = pitch;
this.delay = delay;
}

/**
* 効果音を取得
* @return 効果音
*/
public Sound getSound() {
return sound;
}

/**
* 音量を取得
* @return 音量
*/
public float getVolume() {
return volume;
}

/**
* ピッチを取得
* @return ピッチ
*/
public float getPitch() {
return pitch;
}

/**
* 遅延時間を取得
* @return 遅延時間
*/
public int getDelay() {
return delay;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import co.aikar.commands.MessageKeys;
import co.aikar.commands.MessageType;
import co.aikar.commands.PaperCommandManager;
import com.github.aburaagearou.yatchayatcha.auction.AdminAuction;
import com.github.aburaagearou.yatchayatcha.commands.AdminAuctionCommand;
import com.github.aburaagearou.yatchayatcha.commands.BidCommand;
import com.github.aburaagearou.yatchayatcha.log.AuctionInfo;
import com.github.aburaagearou.yatchayatcha.log.FileLogger;
import com.github.aburaagearou.yatchayatcha.log.IAuctionLogger;
import com.github.aburaagearou.yatchayatcha.log.MemoryLogger;
import com.github.ucchyocean.lc.channel.Channel;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -101,6 +101,9 @@ public void onEnable() {
public void onDisable() {
getLogger().info("YatchaYatchaを無効化します。");

// オークションの中断
AdminAuction.getInstance().end(true);

// コマンドの登録解除
commands.forEach(manager::unregisterCommand);
manager.unregisterCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public void start(ItemStack item, int start, boolean isDebug) {
// 表示
sidebar.showAll();
sidebar.show();

// 効果音
Utilities.playSound(YYConfigUtil.getSoundSetting(YYConfigUtil.SE_START));
}

/**
Expand All @@ -132,10 +135,55 @@ private void cancelTask() {
}
}

/**
* カウントダウンによる自動終了
*/
public void countdown() {
int countdown = YYConfigUtil.getCountdown();

// カウントダウン
final int price = bidPrice;
countdownTask = Bukkit.getScheduler().runTaskTimer(YatchaYatcha.getInstance(), new Runnable() {
int count = countdown;

@Override
public void run() {
if(!isAuctioning) {
cancelTask();
return;
}
if(count-- <= 0) {
end(false);
cancelTask();
return;
}

// 入札があった場合
if(price != bidPrice) {
cancelTask();
return;
}

// 10秒前
if(count == 10) {
Utilities.broadcastColoredMessage("&a&l入札がない場合、あと&e&n" + count + "&a&l秒でオークションが終了します!");
}
else if(count < 5) {
Utilities.playSound(YYConfigUtil.getSoundSetting(YYConfigUtil.SE_COUNTDOWN));
Utilities.broadcastColoredMessage("&e&n" + (count+1) + "...");
}

// サイドバー更新
sidebar.setLine(7, "&b落札まであと&e" + (count+1) + "秒");
}
}, 20L, 20L);
}

/**
* オークションを終了する
*/
public void end(boolean cancel) {
if(!isAuctioning) return;
isAuctioning = false;
if(isDebug) Utilities.broadcastColoredMessage("&c!!!!!!!!!!!!!!!!Debug!!!!!!!!!!!!!!!!");
else Utilities.broadcastColoredMessage("&e=====================================");
Expand Down Expand Up @@ -181,55 +229,15 @@ public void end(boolean cancel) {
if(isDebug) Utilities.broadcastColoredMessage("&c!!!!!!!!!!!!!!!!Debug!!!!!!!!!!!!!!!!");
else Utilities.broadcastColoredMessage("&e=====================================");

// ロギング
YatchaYatcha.log(new AuctionInfo(bidPlayer, bidPrice, item));

// スコアボード使用終了
sidebar.clear();
sidebar.hide();
}

/**
* カウントダウンによる自動終了
*/
public void countdown() {
int countdown = YYConfigUtil.getCountdown();

// カウントダウン
final int price = bidPrice;
countdownTask = Bukkit.getScheduler().runTaskTimer(YatchaYatcha.getInstance(), new Runnable() {
int count = countdown;
// 効果音
Utilities.playSound(YYConfigUtil.getSoundSetting(YYConfigUtil.SE_SUCCESS));

@Override
public void run() {
if(!isAuctioning) {
cancelTask();
return;
}
if(count-- <= 0) {
end(false);
cancelTask();
return;
}

// 入札があった場合
if(price != bidPrice) {
cancelTask();
return;
}

// 10秒前
if(count == 10) {
Utilities.broadcastColoredMessage("&a&l入札がない場合、あと&e&n" + count + "&a&l秒でオークションが終了します!");
}
else if(count < 5) {
Utilities.broadcastColoredMessage("&e&n" + (count+1) + "...");
}

// サイドバー更新
sidebar.setLine(7, "&b落札まであと&e" + (count+1) + "秒");
}
}, 20L, 20L);
// ロギング
YatchaYatcha.log(new AuctionInfo(bidPlayer, bidPrice, item));
}

/**
Expand Down Expand Up @@ -265,6 +273,10 @@ public void bid(Player player, int price) {
sidebar.setLine(4, "&7最高入札額: &e$" + bidPrice);
sidebar.setLine(5, "&e$" + (minPrice.intValue()+1) + "&fから入札可能");

// 効果音
Utilities.playSound(YYConfigUtil.getSoundSetting(YYConfigUtil.SE_BID_SELF), bidPlayer);
Utilities.playSound(YYConfigUtil.getSoundSetting(YYConfigUtil.SE_BID_RIVAL), Bukkit.getOnlinePlayers().stream().filter(p -> !p.equals(bidPlayer)).toArray(Player[]::new));

// カウントダウン開始
cancelTask();
countdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.aburaagearou.yatchayatcha.YatchaYatcha;
import com.github.aburaagearou.yatchayatcha.auction.AdminAuction;
import com.github.aburaagearou.yatchayatcha.utils.Utilities;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -67,15 +66,14 @@ public void onCancel(CommandSender ignore) {
@Description("オークションルールを表示します。")
public void onRule(Player sender) {
for(String rule : YYConfigUtil.getRule()) {
Bukkit.getOnlinePlayers().forEach(player -> Utilities.sendColoredMessage(player, rule));
Utilities.broadcastColoredMessage(rule);
}
}

@Subcommand("reloadconfig")
@Description("コンフィグをリロードします。")
public void onReloadConfig(CommandSender sender) {
plugin.saveDefaultConfig();
plugin.reloadConfig();
YYConfigUtil.reload();
sender.sendMessage("[YatchaYatcha] 設定を再読み込みしました。");
}

Expand Down
Loading

0 comments on commit febeebb

Please sign in to comment.