From 6aac93dc643b8bbb5763961ffb91b761fa34fb09 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 2 Jul 2019 22:56:58 +0200 Subject: [PATCH] added countdown sounds Signed-off-by: Yaruma3341 --- src/me/yaruma/fightsystem/FightSystem.java | 7 ++++--- src/me/yaruma/fightsystem/fight/FightTeam.java | 12 ++++++++---- .../listener/PlayerJoinListener.java | 2 +- .../fightsystem/utils/countdown/Countdown.java | 18 +++++++++++++++++- .../winconditions/WinconditionEntern.java | 3 ++- .../winconditions/WinconditionTimeout.java | 3 ++- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index dd2a10d..fd8fb08 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -16,6 +16,7 @@ import me.yaruma.fightsystem.utils.scoreboard.Scoreboard; import me.yaruma.fightsystem.winconditions.*; import org.bukkit.Bukkit; import org.bukkit.GameMode; +import org.bukkit.Sound; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -96,7 +97,7 @@ public class FightSystem extends JavaPlugin { getCommand("ready").setExecutor(new ReadyCommand()); getCommand("kit").setExecutor(new KitCommand()); - Countdown countdown = new Countdown(Config.NoPlayerOnlineDuration, new FinishNoPlayersOnline()); + Countdown countdown = new Countdown(Config.NoPlayerOnlineDuration, new FinishNoPlayersOnline(), null); countdown.startTimer(getPlugin()); TechHider.init(); @@ -132,7 +133,7 @@ public class FightSystem extends JavaPlugin { fightState = FightState.PRE_RUNNING; Countdown.cancelAllTimers(); - Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning()); + Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning(), Sound.BLOCK_NOTE_PLING); countdown.startTimer(this); for(FightPlayer allFightPlayers : Fight.getBlueTeam().getPlayers()) { allFightPlayers.getPlayer().getInventory().clear(); @@ -209,7 +210,7 @@ public class FightSystem extends JavaPlugin { } } - Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver()); + Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver(), Sound.BLOCK_NOTE_PLING); countdown.startTimer(FightSystem.getPlugin()); } diff --git a/src/me/yaruma/fightsystem/fight/FightTeam.java b/src/me/yaruma/fightsystem/fight/FightTeam.java index 565678c..944226b 100644 --- a/src/me/yaruma/fightsystem/fight/FightTeam.java +++ b/src/me/yaruma/fightsystem/fight/FightTeam.java @@ -20,10 +20,7 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -326,4 +323,11 @@ public class FightTeam { player.spigot().sendMessage(beforePage); } } + + public void playSound(Sound sound, float volume, float pitch) { + for(FightPlayer fightPlayer : players) { + Player player = fightPlayer.getPlayer(); + player.playSound(player.getLocation(), sound, volume, pitch); //volume: max. 100, pitch: max. 2 + } + } } diff --git a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java index a715e85..caa9edc 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java @@ -44,7 +44,7 @@ public class PlayerJoinListener implements Listener { if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader() && FightSystem.getFightState() == FightState.SETUP && (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) { Countdown.cancelTimerType(CountdownType.NO_PLAYERS_ONLINE); - new Countdown(Config.SetupDuration, new FinishSetupOver()).startTimer(FightSystem.getPlugin()); + new Countdown(Config.SetupDuration, new FinishSetupOver(), null).startTimer(FightSystem.getPlugin()); } FightSystem.getPlugin().getScoreboard().setAutoScoreboard(20*10, player); diff --git a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java index b60c0ed..603841f 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java +++ b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java @@ -1,7 +1,9 @@ package me.yaruma.fightsystem.utils.countdown; import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.fight.Fight; import org.bukkit.Bukkit; +import org.bukkit.Sound; import org.bukkit.scheduler.BukkitScheduler; import java.util.ArrayList; @@ -13,10 +15,12 @@ public class Countdown { private int time; private final CountdownCallback countdownCallback; private int taskID; + private Sound sound; - public Countdown(int time, CountdownCallback countdownCallback) { + public Countdown(int time, CountdownCallback countdownCallback, Sound sound) { this.time = time; this.countdownCallback = countdownCallback; + this.sound = sound; countdowns.add(this); } @@ -30,12 +34,24 @@ public class Countdown { Bukkit.broadcastMessage(FightSystem.PREFIX + "§7Noch §a" + time / 60 + " §7Minuten " + countdownCallback.countdownCounting()); break; case 60: case 30: case 20: case 15: case 10: case 5: case 4: case 3: case 2: + if(this.sound != null) { + Fight.getBlueTeam().playSound(this.sound, 100.0F, 1.0F); + Fight.getRedTeam().playSound(this.sound, 100.0F, 1.0F); + } Bukkit.broadcastMessage(FightSystem.PREFIX + "§7Noch §a" + time + " §7Sekunden " + countdownCallback.countdownCounting()); break; case 1: + if(this.sound != null) { + Fight.getBlueTeam().playSound(this.sound, 100.0F, 1.0F); + Fight.getRedTeam().playSound(this.sound, 100.0F, 1.0F); + } Bukkit.broadcastMessage(FightSystem.PREFIX + "§7Noch §aeine §7Sekunde " + countdownCallback.countdownCounting()); break; case 0: + if(this.sound != null) { + Fight.getBlueTeam().playSound(this.sound, 100.0F, 2.0F); + Fight.getRedTeam().playSound(this.sound, 100.0F, 2.0F); + } cancelTimer(); countdownCallback.countdownFinished(); break; diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java b/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java index fe2a96c..6335982 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java @@ -4,6 +4,7 @@ import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.FinishNoneEntern; +import org.bukkit.Sound; public class WinconditionEntern { @@ -12,7 +13,7 @@ public class WinconditionEntern { public static void entern() { if(!Config.Entern) return; - Countdown countdownTimeOver = new Countdown(Config.EnterPhaseBegin, new FinishNoneEntern()); + Countdown countdownTimeOver = new Countdown(Config.EnterPhaseBegin, new FinishNoneEntern(), Sound.BLOCK_NOTE_PLING); countdownTimeOver.startTimer(instance); } diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java b/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java index f148415..b5c99db 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java @@ -4,6 +4,7 @@ import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.FinishTimeOver; +import org.bukkit.Sound; public class WinconditionTimeout { @@ -12,7 +13,7 @@ public class WinconditionTimeout { public static void timeout() { if(!Config.Timeout) return; - Countdown countdownTimeOver = new Countdown(Config.TimeoutTime, new FinishTimeOver()); + Countdown countdownTimeOver = new Countdown(Config.TimeoutTime, new FinishTimeOver(), Sound.BLOCK_NOTE_BASS); countdownTimeOver.startTimer(instance); }