From 72f093b243c07766d1cce808c9a0fccb30227b9d Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 8 Nov 2021 15:53:13 -0500 Subject: [PATCH] 1.3.1 build 6 --- HideAndSeekPlugin.iml | 12 ++++ pom.xml | 16 +---- .../net/tylermurphy/hideAndSeek/Main.java | 16 ++--- .../hideAndSeek/bukkit/EventListener.java | 70 ++++++++++--------- .../tylermurphy/hideAndSeek/bukkit/Tick.java | 8 ++- .../configuration/ConfigManager.java | 1 + .../tylermurphy/hideAndSeek/events/Glow.java | 18 +++-- .../tylermurphy/hideAndSeek/events/Taunt.java | 63 ++++++++--------- .../hideAndSeek/events/Worldborder.java | 32 ++++++--- .../tylermurphy/hideAndSeek/util/Board.java | 15 +++- 10 files changed, 137 insertions(+), 114 deletions(-) create mode 100644 HideAndSeekPlugin.iml diff --git a/HideAndSeekPlugin.iml b/HideAndSeekPlugin.iml new file mode 100644 index 0000000..fa63d4b --- /dev/null +++ b/HideAndSeekPlugin.iml @@ -0,0 +1,12 @@ + + + + + + + SPIGOT + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e0cca85..4d9cd0f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,8 @@ - - - 4.0.0 - +4.0.0 net.tylermurphy HideAndSeek 1.3.1 Hide and Seek Plugin - @@ -22,7 +16,6 @@ - spigot-repo @@ -33,7 +26,6 @@ https://repo.dmulloy2.net/repository/public/ - org.spigotmc @@ -48,10 +40,4 @@ 4.7.0 - - - 11 - 11 - - \ 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 f5c8518..4815a30 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -77,15 +77,13 @@ public class Main extends JavaPlugin implements Listener { board.reload(); // Start Tick Timer - onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){ - public void run(){ - try{ - Tick.onTick(); - } catch (Exception e) { - e.printStackTrace(); - } - } - },0,1); + onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { + try{ + Tick.onTick(); + } catch (Exception e) { + e.printStackTrace(); + } + },0,1); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java index 2e8eafb..ffad241 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/EventListener.java @@ -82,43 +82,47 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamage(EntityDamageEvent event) { - if(event.getEntity() instanceof Player) { - Player p = (Player) event.getEntity(); - if(!Main.plugin.board.isPlayer(p)) return; - if(!Main.plugin.status.equals("Playing")) { - event.setCancelled(true); - return; - } - Player attacker = null; - if(event instanceof EntityDamageByEntityEvent) { - Entity damager = ((EntityDamageByEntityEvent)event).getDamager(); - if(damager instanceof Player) { - attacker = (Player) damager; - if(Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true); - if(Main.plugin.board.isSpectator(p)) event.setCancelled(true); - } - } - Player player = (Player) event.getEntity(); - if(player.getHealth()-event.getDamage() < 0 || !pvpEnabled) { - if(spawnPosition == null) return; - event.setCancelled(true); - player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); - Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); - if(Main.plugin.board.isSeeker(player)) { - Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); + try { + if (event.getEntity() instanceof Player) { + Player p = (Player) event.getEntity(); + if (!Main.plugin.board.isPlayer(p)) return; + if (!Main.plugin.status.equals("Playing")) { + event.setCancelled(true); + return; } - if(Main.plugin.board.isHider(player)) { - if(attacker == null) { - Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); - } else { - Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); + Player attacker = null; + if (event instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); + if (damager instanceof Player) { + attacker = (Player) damager; + if (Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true); + if (Main.plugin.board.isSpectator(p)) event.setCancelled(true); } - Main.plugin.board.addSeeker(player); } - Util.resetPlayer(player); - Main.plugin.board.reloadBoardTeams(); + Player player = (Player) event.getEntity(); + if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { + if (spawnPosition == null) return; + event.setCancelled(true); + player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); + if (Main.plugin.board.isSeeker(player)) { + Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString()); + } + if (Main.plugin.board.isHider(player)) { + if (attacker == null) { + Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString()); + } else { + Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString()); + } + Main.plugin.board.addSeeker(player); + } + Util.resetPlayer(player); + Main.plugin.board.reloadBoardTeams(); + } } + } catch (Exception e){ + //Has shown to cause problems, so ignore if exception } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java index eadcf14..8efbe80 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/bukkit/Tick.java @@ -40,9 +40,13 @@ public class Tick { else tick = 1; for(Player hider : Main.plugin.board.getHiders()) { - int distance = 100; + int distance = 100, temp = 100; for(Player seeker : Main.plugin.board.getSeekers()) { - int temp = (int) hider.getLocation().distance(seeker.getLocation()); + try { + temp = (int) hider.getLocation().distance(seeker.getLocation()); + } catch (Exception e){ + //Players in different worlds, NOT OK!!! + } if(distance > temp) { distance = temp; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index df970bf..09b3dcf 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -125,6 +125,7 @@ public class ConfigManager { if(index == -1) continue;; int start = yamlString.indexOf(' ', index); int end = yamlString.indexOf('\n', index); + if(end == -1) end = yamlString.length(); String replace = entry.getValue().toString(); if(entry.getValue() instanceof String){ replace = "\"" + replace + "\""; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java index 6ea5ab8..a817df3 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Glow.java @@ -37,16 +37,14 @@ public class Glow { } private void waitGlow() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - glowTime--; - glowTime = Math.max(glowTime, 0); - if(glowTime == 0) { - stopGlow(); - } else { - waitGlow(); - } + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(temp != Main.plugin.gameId) return; + glowTime--; + glowTime = Math.max(glowTime, 0); + if(glowTime == 0) { + stopGlow(); + } else { + waitGlow(); } }, 20); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java index 748ae40..d24c93f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Taunt.java @@ -32,20 +32,19 @@ public class Taunt { } private void waitTaunt() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - if(delay == 0) { - if(!tauntLast && Main.plugin.board.size() < 2) return; - else executeTaunt(); - } else { - delay--; - waitTaunt(); - } + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(delay == 0) { + if(!tauntLast && Main.plugin.board.size() < 2) return; + else executeTaunt(); + } else { + delay--; + waitTaunt(); } },20); } private void executeTaunt() { + if(temp != Main.plugin.gameId) return; Player taunted = null; int rand = (int) (Math.random()*Main.plugin.board.sizeHider()); for(Player player : Main.plugin.board.getPlayers()) { @@ -62,31 +61,29 @@ public class Taunt { taunted.sendMessage(message("TAUNTED").toString()); Util.broadcastMessage(tauntPrefix + message("TAUNT")); tauntPlayer = taunted.getName(); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - Player taunted = Main.plugin.board.getPlayer(tauntPlayer); - if(taunted != null) { - Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK); - FireworkMeta fwm = fw.getFireworkMeta(); - fwm.setPower(4); - fwm.addEffect(FireworkEffect.builder() - .withColor(Color.BLUE) - .withColor(Color.RED) - .withColor(Color.YELLOW) - .with(FireworkEffect.Type.STAR) - .with(FireworkEffect.Type.BALL) - .with(FireworkEffect.Type.BALL_LARGE) - .flicker(true) - .withTrail() - .build()); - fw.setFireworkMeta(fwm); - Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); - } - tauntPlayer = ""; - running = false; - schedule(); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(temp != Main.plugin.gameId) return; + Player taunted1 = Main.plugin.board.getPlayer(tauntPlayer); + if(taunted1 != null) { + Firework fw = (Firework) taunted1.getLocation().getWorld().spawnEntity(taunted1.getLocation(), EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + fwm.setPower(4); + fwm.addEffect(FireworkEffect.builder() + .withColor(Color.BLUE) + .withColor(Color.RED) + .withColor(Color.YELLOW) + .with(FireworkEffect.Type.STAR) + .with(FireworkEffect.Type.BALL) + .with(FireworkEffect.Type.BALL_LARGE) + .flicker(true) + .withTrail() + .build()); + fw.setFireworkMeta(fwm); + Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE")); } + tauntPlayer = ""; + running = false; + schedule(); },20*30); } else { schedule(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java index 5884a94..5d0e48c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/events/Worldborder.java @@ -13,32 +13,38 @@ import net.tylermurphy.hideAndSeek.util.Util; public class Worldborder { private final int temp; + private int delay; + private boolean running; public Worldborder(int temp) { this.temp = temp; } public void schedule() { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - decreaceWorldborder(); + delay = 60*worldborderDelay; + running = false; + waitBorder(); + } + + private void waitBorder(){ + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> { + if(delay == 0) decreaceWorldborder(); + else { + delay--; waitBorder(); } - },20*60*worldborderDelay); + }, 20); } private void decreaceWorldborder() { if(temp != Main.plugin.gameId) return; if(currentWorldborderSize-100 > 100) { + running = true; Util.broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING")); currentWorldborderSize -= 100; World world = Bukkit.getWorld("hideandseek_"+spawnWorld); WorldBorder border = world.getWorldBorder(); border.setSize(border.getSize()-100,30); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() { - public void run() { - decreaceWorldborder(); - } - },20*60*worldborderDelay); + schedule(); } } @@ -56,5 +62,13 @@ public class Worldborder { border.setCenter(0, 0); } } + + public int getDelay(){ + return delay; + } + + public boolean isRunning() { + return running; + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java index 80cbdee..9d856b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Board.java @@ -180,13 +180,13 @@ public class Board { board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); board.addBlank(); if(glowEnabled){ - if(Main.plugin.glow == null || !Main.plugin.glow.isRunning()) + if(Main.plugin.glow == null || Main.plugin.status.equals("Starting") || !Main.plugin.glow.isRunning()) board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); else board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); } if(tauntEnabled && tauntCountdown){ - if(Main.plugin.taunt == null) + if(Main.plugin.taunt == null || Main.plugin.status.equals("Starting")) board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); else if(!tauntLast && Hider.size() == 1){ board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); @@ -195,7 +195,16 @@ public class Board { else board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); } - if(glowEnabled || (tauntEnabled && tauntCountdown)) + if(worldborderEnabled){ + if(Main.plugin.worldborder == null || Main.plugin.status.equals("Starting")){ + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); + } else if(!Main.plugin.worldborder.isRunning()) { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.worldborder.getDelay()/60 + "m" + Main.plugin.worldborder.getDelay()%60 + "s"); + } else { + board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); + } + } + if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) board.addBlank(); board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s"); board.addBlank();