From dc731b425f2765f2c6480245c5570eedcf05b506 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 21 Aug 2021 20:08:11 -0400 Subject: [PATCH] 1.1.0 --- pom.xml | 69 ++++++++------ .../net/tylermurphy/hideAndSeek/Main.java | 9 +- .../hideAndSeek/commands/About.java | 2 +- .../commands/SetSpawnLocation.java | 5 +- .../hideAndSeek/commands/Start.java | 56 +++++++---- .../hideAndSeek/commands/Stop.java | 2 +- .../hideAndSeek/manager/BoardManager.java | 40 -------- .../hideAndSeek/manager/EventManager.java | 56 ++++++++--- .../hideAndSeek/manager/TickManager.java | 36 +++---- .../manager/WorldborderManager.java | 14 ++- .../hideAndSeek/util/Functions.java | 95 +++++++++++-------- src/main/resources/plugin.yml | 4 +- 12 files changed, 214 insertions(+), 174 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/manager/BoardManager.java diff --git a/pom.xml b/pom.xml index 85bc166..3ab63ff 100644 --- a/pom.xml +++ b/pom.xml @@ -1,34 +1,43 @@ - - 4.0.0 - net.tylermurphy - HideAndSeek - 1.0.0 - Hide and Seek Plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - +4.0.0 + net.tylermurphy + HideAndSeek + 1.1.0 + Hide and Seek Plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/public/ + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/public/ - - - - org.spigotmc - spigot-api - 1.17.1-R0.1-SNAPSHOT - jar - provided - + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + + + + org.spigotmc + spigot-api + 1.17.1-R0.1-SNAPSHOT + jar + provided + + + com.comphenix.protocol + ProtocolLib + 4.7.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 05b853e..c96ee5f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -14,6 +14,7 @@ import org.bukkit.util.Vector; import net.tylermurphy.hideAndSeek.manager.CommandManager; import net.tylermurphy.hideAndSeek.manager.EventManager; import net.tylermurphy.hideAndSeek.manager.TickManager; +import net.tylermurphy.hideAndSeek.util.Functions; public class Main extends JavaPlugin implements Listener { @@ -43,14 +44,6 @@ public class Main extends JavaPlugin implements Listener { } worldborderEnabled = getConfig().getBoolean("borderEnabled"); - // Init Gamerules - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule sendCommandFeedback false"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule doImmediateRespawn true"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule logAdminCommands false"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule naturalRegeneration false"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule keepInventory true"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule showDeathMessages false"); - // Register Commands CommandManager.registerCommands(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java index 91cc430..7c00369 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/About.java @@ -9,7 +9,7 @@ public class About implements ICommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(1.0.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(1.1.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java index 821d469..b341584 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/SetSpawnLocation.java @@ -1,6 +1,5 @@ package net.tylermurphy.hideAndSeek.commands; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -26,8 +25,8 @@ public class SetSpawnLocation implements ICommand { sender.sendMessage(messagePrefix + "Set spawn position to current location"); getConfig().set("spawnPosition", newSpawnPosition); saveConfig(); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("setworldspawn %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); +// Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("setworldspawn %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); +// Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); } public String getLabel() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java index 50dbc4f..d087839 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/Start.java @@ -17,8 +17,6 @@ import net.tylermurphy.hideAndSeek.util.Functions; import static net.tylermurphy.hideAndSeek.Store.*; -import java.util.HashMap; - public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { @@ -39,8 +37,6 @@ public class Start implements ICommand { return; } - Functions.setGamerules(); - for(Player player : playerList.values()) { player.getInventory().clear(); player.setGameMode(GameMode.ADVENTURE); @@ -49,7 +45,7 @@ public class Start implements ICommand { player.removePotionEffect(effect.getType()); } } - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", spawnPosition.getBlockX(), spawnPosition.getBlockY(), spawnPosition.getBlockZ())); + //Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", spawnPosition.getBlockX(), spawnPosition.getBlockY(), spawnPosition.getBlockZ())); for(String playerName : Seeker.getEntries()) { Player player = playerList.get(playerName); if(player != null) { @@ -65,34 +61,62 @@ public class Start implements ICommand { } WorldborderManager.reset(); status = "Starting"; - Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){ + int temp = gameId; + Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { public void run() { - int temp = gameId; - Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!"); - try { Thread.sleep(10*1000); } catch (InterruptedException e) {} if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!"); - try { Thread.sleep(10*1000); } catch (InterruptedException e) {} + } + }, 20 * 10); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!"); - try { Thread.sleep(5*1000); } catch (InterruptedException e) {} + } + }, 20 * 20); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!"); - try { Thread.sleep(2*1000); } catch (InterruptedException e) {} + } + }, 20 * 25); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!"); - try { Thread.sleep(1*1000); } catch (InterruptedException e) {} + } + }, 20 * 27); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!"); - try { Thread.sleep(1*1000); } catch (InterruptedException e) {} + } + }, 20 * 28); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!"); - try { Thread.sleep(1*1000); } catch (InterruptedException e) {} + } + }, 20 * 29); + + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { if(temp != gameId) return; Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!"); status = "Playing"; + for(Player player : playerList.values()) { + Functions.resetPlayer(player); + } } - }); + }, 20 * 30); + if(worldborderEnabled) { WorldborderManager.schedule(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java index 71d0035..87abf49 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/commands/Stop.java @@ -33,6 +33,7 @@ public class Stop implements ICommand { public static void onStop() { if(status.equals("Standby") || status.equals("Setup")) return; status = "Standby"; + gameId++; for(Player player : playerList.values()) { player.setGameMode(GameMode.ADVENTURE); Hider.addEntry(player.getName()); @@ -44,7 +45,6 @@ public class Stop implements ICommand { player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); } WorldborderManager.reset(); - gameId++; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/BoardManager.java b/src/main/java/net/tylermurphy/hideAndSeek/manager/BoardManager.java deleted file mode 100644 index db618b5..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/BoardManager.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.tylermurphy.hideAndSeek.manager; - -import static net.tylermurphy.hideAndSeek.Store.*; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.ScoreboardManager; -import org.bukkit.scoreboard.Team.Option; -import org.bukkit.scoreboard.Team.OptionStatus; - -public class BoardManager { - - public static void loadScoreboard() { - - ScoreboardManager manager = Bukkit.getScoreboardManager(); - Scoreboard mainBoard = manager.getMainScoreboard(); - - try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {} - Seeker = mainBoard.getTeam("Seeker"); - Seeker.setColor(ChatColor.RED); - Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - Seeker.setAllowFriendlyFire(false); - - try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {} - Hider = mainBoard.getTeam("Hider"); - Hider.setColor(ChatColor.GOLD); - Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - Hider.setAllowFriendlyFire(false); - - try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {} - Spectator = mainBoard.getTeam("Spectator"); - Spectator.setColor(ChatColor.GRAY); - Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - Spectator.setAllowFriendlyFire(false); - - board = mainBoard; - } - -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java b/src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java index 129d684..9983202 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/manager/EventManager.java @@ -5,26 +5,29 @@ import static net.tylermurphy.hideAndSeek.Store.*; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.potion.PotionEffect; import net.md_5.bungee.api.ChatColor; +import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.Functions; public class EventManager implements Listener { - + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if(Bukkit.getScoreboardManager() != null && board == null) { - BoardManager.loadScoreboard(); - } if(status.equals("Playing") || status.equals("Starting")) { Spectator.addEntry(event.getPlayer().getName()); event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team."); @@ -49,18 +52,28 @@ public class EventManager implements Listener { } @EventHandler - public void onDeath(PlayerDeathEvent event) { - if(status.equals("Playing")) { - if(Hider.hasEntry(event.getEntity().getName())) { - Bukkit.getServer().broadcastMessage(String.format(messagePrefix + "%s%s%s has died and become a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE)); + public void onPlayerDamage(EntityDamageEvent event) { + if(event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if(player.getHealth()-event.getDamage() < 0) { + if(spawnPosition == null) return; + event.setCancelled(true); + player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + player.teleport(new Location(player.getWorld(), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); + Functions.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); + if(status.equals("Playing")) { + Functions.resetPlayer(player); + if(Hider.hasEntry(event.getEntity().getName())) { + Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s has died and become a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE)); + } + if(Seeker.hasEntry(event.getEntity().getName())) { + Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s has been beat by a hider", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE)); + } + Seeker.addEntry(player.getName()); + } } - if(Seeker.hasEntry(event.getEntity().getName())) { - Bukkit.getServer().broadcastMessage(String.format(messagePrefix + "%s%s%s has been beat by a hider", ChatColor.RED, event.getEntity().getName(), ChatColor.WHITE)); - } - - Functions.giveItems(event.getEntity()); - Seeker.addEntry(event.getEntity().getName()); } + } @EventHandler @@ -73,9 +86,22 @@ public class EventManager implements Listener { if(Hider.hasEntry(player.getName())) { glowTime++; snowball.remove(); + player.getInventory().remove(Material.SNOWBALL); + int temp = gameId; + Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { + public void run() { + if(temp != gameId) return; + glowTime--; + } + }, 20 * 30); } } } } + @EventHandler + public void onPlayerRegainHealth(EntityRegainHealthEvent event) { + if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) + event.setCancelled(true); + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java b/src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java index 974dae3..10c7c84 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/manager/TickManager.java @@ -7,6 +7,9 @@ import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.WorldBorder; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; import org.bukkit.entity.Player; @@ -23,9 +26,11 @@ public class TickManager { public static void onTick() { - if(board == null) return; + if(board == null) { + Functions.loadScoreboard(); + } - Functions.checkTeams(); + Functions.emptyOfflinePlayers(); for(Player player : playerList.values()) { player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 1000000, 127, false, false)); @@ -41,11 +46,11 @@ public class TickManager { tick ++; - if(Hider.getSize() < 1) { + if(( status.equals("Starting") || status.equals("Playing") ) && Hider.getSize() < 1) { Bukkit.broadcastMessage(messagePrefix + "Game over! All hiders have been found."); Stop.onStop(); } - if(Seeker.getSize() < 1) { + if(( status.equals("Starting") || status.equals("Playing") ) && Seeker.getSize() < 1) { Bukkit.broadcastMessage(messagePrefix + "Game has ended as all seekers have quit."); Stop.onStop(); } @@ -55,6 +60,7 @@ public class TickManager { for(Player player : playerList.values()) { player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 1000000, 127, false, false)); } + } private static void onStarting() { @@ -68,7 +74,9 @@ public class TickManager { private static void onPlaying() { if(decreaseBorder) { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder add -100 30"); + World world = Bukkit.getWorld("world"); + WorldBorder border = world.getWorldBorder(); + border.setSize(border.getSize()-100,30); decreaseBorder = false; } if(!tauntPlayer.equals("")) { @@ -122,29 +130,23 @@ public class TickManager { distance = temp; } } - int x = player.getLocation().getBlockX(); - int y = player.getLocation().getBlockY(); - int z = player.getLocation().getBlockZ(); switch(tick%10) { case 0: - if(distance < 30) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.basedrum master %s %s %s %s .5 1",player.getName(),x,y,z)); - if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z)); + if(distance < 30) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); + if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; case 3: - if(distance < 30) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.basedrum master %s %s %s %s 3.31",player.getName(),x,y,z)); - if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z)); + if(distance < 30) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); + if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; case 6: - if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z)); + if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; case 9: - if(distance < 20) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z)); + if(distance < 20) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); break; } } - if(tick%(20*30) == 0) { - glowTime = Math.max(0, glowTime--); - } } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java b/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java index aa0011c..c695d1d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/manager/WorldborderManager.java @@ -3,6 +3,8 @@ package net.tylermurphy.hideAndSeek.manager; import static net.tylermurphy.hideAndSeek.Store.*; import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldBorder; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; @@ -32,12 +34,16 @@ public class WorldborderManager { public static void reset() { if(worldborderEnabled) { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder set "+worldborderSize); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("worldborder center %s %s",worldborderPosition.getBlockX(),worldborderPosition.getBlockZ())); + World world = Bukkit.getWorld("world"); + WorldBorder border = world.getWorldBorder(); + border.setSize(worldborderSize); + border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ()); currentWorldborderSize = worldborderSize; } else { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder set 30000000"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder center 0 0"); + World world = Bukkit.getWorld("world"); + WorldBorder border = world.getWorldBorder(); + border.setSize(30000000); + border.setCenter(0, 0); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java index 05db0e0..73e0fb0 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Functions.java @@ -6,12 +6,14 @@ import static net.tylermurphy.hideAndSeek.Store.Spectator; import static net.tylermurphy.hideAndSeek.Store.board; import static net.tylermurphy.hideAndSeek.Store.playerList; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -20,21 +22,22 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionType; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.ScoreboardManager; import org.bukkit.scoreboard.Team.Option; import org.bukkit.scoreboard.Team.OptionStatus; -public class Functions { +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; - public static void setGamerules() { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule sendCommandFeedback false"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule doImmediateRespawn true"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule logAdminCommands false"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule naturalRegeneration false"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule keepInventory true"); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule showDeathMessages false"); - } +public class Functions { - public static void giveItems(Player player) { + private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + + public static void resetPlayer(Player player) { player.getInventory().clear(); for(PotionEffect effect : player.getActivePotionEffects()){ player.removePotionEffect(effect.getType()); @@ -84,37 +87,11 @@ public class Functions { snowballLore.add("Last 30s, all hiders can see it"); snowballLore.add("Time stacks on multi use"); snowballMeta.setLore(snowballLore); + player.getInventory().addItem(snowball); } } - public static void checkTeams() { - - try { Hider.getSize(); } - catch (Exception e) { - board.registerNewTeam("Hider"); - Hider = board.getTeam("Hider"); - Hider.setColor(ChatColor.GOLD); - Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - Hider.setAllowFriendlyFire(false); - } - - try { Seeker.getSize(); } - catch (Exception e) { - board.registerNewTeam("Seeker"); - Seeker = board.getTeam("Seeker"); - Seeker.setColor(ChatColor.RED); - Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - Seeker.setAllowFriendlyFire(false); - } - - try { Spectator.getSize(); } - catch (Exception e) { - board.registerNewTeam("Spectator"); - Spectator = board.getTeam("Spectator"); - Spectator.setColor(ChatColor.GRAY); - Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); - Spectator.setAllowFriendlyFire(false); - } + public static void emptyOfflinePlayers() { for(String entry : Hider.getEntries()) { if(!playerList.containsKey(entry)) { @@ -135,4 +112,46 @@ public class Functions { } } + public static void loadScoreboard() { + + ScoreboardManager manager = Bukkit.getScoreboardManager(); + Scoreboard mainBoard = manager.getMainScoreboard(); + + try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {} + Seeker = mainBoard.getTeam("Seeker"); + Seeker.setColor(ChatColor.RED); + Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); + Seeker.setAllowFriendlyFire(false); + + try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {} + Hider = mainBoard.getTeam("Hider"); + Hider.setColor(ChatColor.GOLD); + Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); + Hider.setAllowFriendlyFire(false); + + try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {} + Spectator = mainBoard.getTeam("Spectator"); + Spectator.setColor(ChatColor.GRAY); + Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER); + Spectator.setAllowFriendlyFire(false); + + board = mainBoard; + } + + public static void playSound(Player player, Sound sound, float volume, float pitch) { + PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT); + packet.getSoundCategories().write(0, SoundCategory.MASTER); + packet.getSoundEffects().write(0, sound); + packet.getIntegers().write(0, (int)(player.getLocation().getX() * 8.0)); + packet.getIntegers().write(1, (int)(player.getLocation().getY() * 8.0)); + packet.getIntegers().write(2, (int)(player.getLocation().getZ() * 8.0)); + packet.getFloat().write(0, volume); + packet.getFloat().write(1, pitch); + try { + protocolManager.sendServerPacket(player, packet); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ea176f0..5f5ddb2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,10 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.0 +version: 1.1.0 author: KenshinEto load: STARTUP +api-version: 1.17 +depend: [ProtocolLib] commands: hideandseek: description: Hide and Seek command