diff --git a/pom.xml b/pom.xml index 7c10eb1..7e48a1c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,5 +44,10 @@ sqlite-jdbc 3.36.0.3 + + org.jetbrains + annotations + 23.0.0 + \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index f1b3364..e486cda 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -40,6 +40,7 @@ import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.game.Board; +import org.jetbrains.annotations.NotNull; public class Main extends JavaPlugin implements Listener { @@ -77,12 +78,12 @@ public class Main extends JavaPlugin implements Listener { UUIDFetcher.cleanup(); } - public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { return CommandHandler.handleCommand(sender, args); } - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { return TabCompleter.handleTabComplete(sender, args); } -} +} \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 4911d5f..7db663c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import net.tylermurphy.hideAndSeek.command.Join; import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.*; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 39d6376..f8284ca 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -411,7 +411,7 @@ class Taunt { protected void update() { if(delay == 0) { if(running) launchTaunt(); - else if(tauntLast || Board.size() > 1) executeTaunt(); + else if(tauntLast || Board.sizeHider() > 1) executeTaunt(); } else { delay--; delay = Math.max(delay, 0); @@ -419,34 +419,31 @@ class Taunt { } private void executeTaunt() { - Player taunted = null; - int rand = (int) (Math.random()*Board.sizeHider()); - for(Player player : Board.getPlayers()) { - if(Board.isHider(player)) { - rand--; - if(rand==0) { - taunted = player; - break; - } - } - } - if(taunted != null) { - taunted.sendMessage(message("TAUNTED").toString()); - broadcastMessage(tauntPrefix + message("TAUNT")); - tauntPlayer = taunted.getName(); - running = true; - delay = 30; - } else { - this.delay = tauntDelay; + Optional rand = Board.getHiders().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; } + Player taunted = rand.get(); + taunted.sendMessage(message("TAUNTED").toString()); + broadcastMessage(tauntPrefix + message("TAUNT")); + tauntPlayer = taunted.getName(); + running = true; + delay = 30; } private void launchTaunt(){ - Player taunted1 = Board.getPlayer(tauntPlayer); - if(taunted1 != null) { - World world = taunted1.getLocation().getWorld(); - assert world != null; - Firework fw = (Firework) world.spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); + Player taunted = Board.getPlayer(tauntPlayer); + if(taunted != null) { + World world = taunted.getLocation().getWorld(); + if(world == null){ + Main.plugin.getLogger().severe("Game world is null while trying to launch taunt."); + tauntPlayer = ""; + running = false; + delay = tauntDelay; + return; + } + Firework fw = (Firework) world.spawnEntity(taunted.getLocation(), EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); fwm.setPower(4); fwm.addEffect(FireworkEffect.builder() diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java index 7f29d6a..7b12767 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/VoidGenerator.java @@ -26,11 +26,12 @@ import java.util.Random; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; +import org.jetbrains.annotations.NotNull; public class VoidGenerator extends ChunkGenerator{ - public List getDefaultPopulators(World world) { - return Collections.emptyList(); + public @NotNull List getDefaultPopulators(@NotNull World world) { + return Collections.emptyList(); } public boolean shouldGenerateNoise() { @@ -61,10 +62,11 @@ public class VoidGenerator extends ChunkGenerator{ return false; } - public boolean canSpawn(World world, int x, int z) { + public boolean canSpawn(@NotNull World world, int x, int z) { return true; } - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { return createChunkData(world); } - + // Backwards compatibility + public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { return createChunkData(world); } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ae130f8..778e3b4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -90,7 +90,6 @@ lobby: max: 10 enabled: true - # Changes the default plugin language. Currently, Supported localizations are: # en-US (English - United States) # de-DE (German - Germany)