From f72c5b224ae4ef4288b858ca5acee16474320135 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 4 Jul 2019 22:07:12 +0200 Subject: [PATCH] rework of countdown sounds Signed-off-by: Yaruma3341 --- src/me/yaruma/fightsystem/FightSystem.java | 6 ++-- src/me/yaruma/fightsystem/fight/Fight.java | 14 ++++++++++ .../yaruma/fightsystem/fight/FightTeam.java | 7 ----- .../listener/PlayerDeathListener.java | 3 ++ .../listener/PlayerJoinListener.java | 2 +- .../utils/countdown/Countdown.java | 28 ++++++++++--------- .../winconditions/WinconditionEntern.java | 2 +- .../winconditions/WinconditionTimeout.java | 2 +- 8 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index fd8fb08..1c1a37a 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -97,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(), null); + Countdown countdown = new Countdown(Config.NoPlayerOnlineDuration, new FinishNoPlayersOnline(), null, false); countdown.startTimer(getPlugin()); TechHider.init(); @@ -133,7 +133,7 @@ public class FightSystem extends JavaPlugin { fightState = FightState.PRE_RUNNING; Countdown.cancelAllTimers(); - Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning(), Sound.BLOCK_NOTE_PLING); + Countdown countdown = new Countdown(Config.PreFightDuration, new FinishPreRunning(), Sound.BLOCK_NOTE_PLING, true); countdown.startTimer(this); for(FightPlayer allFightPlayers : Fight.getBlueTeam().getPlayers()) { allFightPlayers.getPlayer().getInventory().clear(); @@ -210,7 +210,7 @@ public class FightSystem extends JavaPlugin { } } - Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver(), Sound.BLOCK_NOTE_PLING); + Countdown countdown = new Countdown(Config.SpectatorDuration, new FinishSpectateOver(), Sound.BLOCK_NOTE_PLING, false); countdown.startTimer(FightSystem.getPlugin()); } diff --git a/src/me/yaruma/fightsystem/fight/Fight.java b/src/me/yaruma/fightsystem/fight/Fight.java index c8c4452..fd5be52 100644 --- a/src/me/yaruma/fightsystem/fight/Fight.java +++ b/src/me/yaruma/fightsystem/fight/Fight.java @@ -1,6 +1,8 @@ package me.yaruma.fightsystem.fight; import me.yaruma.fightsystem.utils.Config; +import org.bukkit.Bukkit; +import org.bukkit.Sound; import org.bukkit.entity.Player; public class Fight { @@ -48,4 +50,16 @@ public class Fight { public static FightTeam getBlueTeam() { return blueTeam; } + + public static void playSound(Sound sound, float volume, float pitch) { + for(Player player : Bukkit.getServer().getOnlinePlayers()) { + player.playSound(player.getLocation(), sound, volume, pitch); //volume: max. 100, pitch: max. 2 + } + } + + public static void setLevel(int level) { + for(Player player : Bukkit.getServer().getOnlinePlayers()) { + player.setLevel(level); + } + } } diff --git a/src/me/yaruma/fightsystem/fight/FightTeam.java b/src/me/yaruma/fightsystem/fight/FightTeam.java index 944226b..b07216d 100644 --- a/src/me/yaruma/fightsystem/fight/FightTeam.java +++ b/src/me/yaruma/fightsystem/fight/FightTeam.java @@ -323,11 +323,4 @@ 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/PlayerDeathListener.java b/src/me/yaruma/fightsystem/listener/PlayerDeathListener.java index c14e727..3b065df 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerDeathListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerDeathListener.java @@ -5,6 +5,7 @@ import me.yaruma.fightsystem.fight.Fight; import me.yaruma.fightsystem.fight.FightTeam; import me.yaruma.fightsystem.utils.Config; import org.bukkit.GameMode; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,6 +28,8 @@ public class PlayerDeathListener implements Listener { player.teleport(Config.TeamRedSpawn); else player.teleport(Config.TeamBlueSpawn); + + Fight.playSound(Sound.ENTITY_WITHER_DEATH, 100.0F, 1.0F); } diff --git a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java index caa9edc..1a9e717 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(), null).startTimer(FightSystem.getPlugin()); + new Countdown(Config.SetupDuration, new FinishSetupOver(), null, false).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 603841f..7c6fd07 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java +++ b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java @@ -16,11 +16,13 @@ public class Countdown { private final CountdownCallback countdownCallback; private int taskID; private Sound sound; + private boolean level; - public Countdown(int time, CountdownCallback countdownCallback, Sound sound) { + public Countdown(int time, CountdownCallback countdownCallback, Sound sound, boolean level) { this.time = time; this.countdownCallback = countdownCallback; this.sound = sound; + this.level = level; countdowns.add(this); } @@ -34,28 +36,28 @@ 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); - } + if(this.sound != null) + Fight.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); - } + if(this.sound != null) + Fight.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); - } + if(this.sound != null) + Fight.playSound(this.sound, 100.0F, 2.0F); + cancelTimer(); countdownCallback.countdownFinished(); break; } + if(this.level) + Fight.setLevel(time); + time--; if(countdownCallback instanceof FinishTimeOver) FightSystem.setFightTime(time); }, 0, 20); diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java b/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java index 6335982..d5624b0 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionEntern.java @@ -13,7 +13,7 @@ public class WinconditionEntern { public static void entern() { if(!Config.Entern) return; - Countdown countdownTimeOver = new Countdown(Config.EnterPhaseBegin, new FinishNoneEntern(), Sound.BLOCK_NOTE_PLING); + Countdown countdownTimeOver = new Countdown(Config.EnterPhaseBegin, new FinishNoneEntern(), Sound.BLOCK_NOTE_PLING, false); countdownTimeOver.startTimer(instance); } diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java b/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java index b5c99db..6f87140 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionTimeout.java @@ -13,7 +13,7 @@ public class WinconditionTimeout { public static void timeout() { if(!Config.Timeout) return; - Countdown countdownTimeOver = new Countdown(Config.TimeoutTime, new FinishTimeOver(), Sound.BLOCK_NOTE_BASS); + Countdown countdownTimeOver = new Countdown(Config.TimeoutTime, new FinishTimeOver(), Sound.BLOCK_NOTE_BASS, false); countdownTimeOver.startTimer(instance); }