From e9daa954737864b124e7b4d0d29f8fa24da70e22 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Apr 2022 12:36:11 -0400 Subject: [PATCH 1/7] 1.4.0 initial --- pom.xml | 58 ++++++- .../hideAndSeek/command/About.java | 2 +- .../hideAndSeek/configuration/Config.java | 21 ++- .../configuration/ConfigManager.java | 14 ++ .../hideAndSeek/configuration/Items.java | 38 ++++- .../configuration/Localization.java | 6 +- .../hideAndSeek/database/Database.java | 7 + .../tylermurphy/hideAndSeek/game/Board.java | 39 ++++- .../hideAndSeek/game/EventListener.java | 25 ++- .../tylermurphy/hideAndSeek/game/Game.java | 58 +++++-- .../tylermurphy/hideAndSeek/util/Packet.java | 24 ++- .../tylermurphy/hideAndSeek/util/Version.java | 45 +++++ .../util/protocollib/AbstractPacket.java | 115 +++++++++++++ .../WrapperPlayServerNamedSoundEffect.java | 158 ++++++++++++++++++ .../hideAndSeek/world/WorldLoader.java | 18 +- src/main/resources/config.yml | 12 +- src/main/resources/plugin.yml | 12 +- 17 files changed, 579 insertions(+), 73 deletions(-) create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/Version.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java diff --git a/pom.xml b/pom.xml index 7e48a1c..d029bea 100644 --- a/pom.xml +++ b/pom.xml @@ -1,8 +1,11 @@ 4.0.0 net.tylermurphy HideAndSeek - 1.3.3 + 1.4.0 Hide and Seek Plugin + + UTF-8 + @@ -14,6 +17,50 @@ 8 + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + false + + + com.cryptomorin.xseries + net.tylermurphy.hideAndSeek.util.xseries + + + + + com.github.cryptomorin:XSeries + org.xerial:sqlite-jdbc + + + + + *:* + + META-INF/*.MF + com/cryptomorin/xseries/XBiome* + com/cryptomorin/xseries/NMSExtras* + com/cryptomorin/xseries/NoteBlockMusic* + com/cryptomorin/xseries/SkullCacheListener* + com/cryptomorin/xseries/XBlock* + com/cryptomorin/xseries/XEntity* + com/cryptomorin/xseries/particles/* + com/cryptomorin/xseries/messages/ActionBar* + + + + + + + package + + shade + + + + @@ -30,7 +77,7 @@ org.spigotmc spigot-api - 1.18.1-R0.1-SNAPSHOT + 1.9-R0.1-SNAPSHOT jar provided @@ -43,11 +90,18 @@ org.xerial sqlite-jdbc 3.36.0.3 + jar + provided org.jetbrains annotations 23.0.0 + + com.github.cryptomorin + XSeries + 8.7.1 + \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java index de1062b..bfc6c85 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java @@ -26,7 +26,7 @@ public class About implements ICommand { public void execute(CommandSender sender, String[] args) { sender.sendMessage( - String.format("%s%sHide and Seek %s(%s1.3.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + + String.format("%s%sHide and Seek %s(%s1.4.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/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 524eeac..98b27b2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -19,6 +19,7 @@ package net.tylermurphy.hideAndSeek.configuration; +import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.util.Vector; public class Config { @@ -36,7 +37,7 @@ public class Config { spawnWorld, exitWorld, lobbyWorld, - local; + locale; public static Vector spawnPosition, @@ -57,7 +58,8 @@ public class Config { pvpEnabled, autoJoin, teleportToExit, - lobbyCountdownEnabled; + lobbyCountdownEnabled, + seekerPing; public static int minPlayers, @@ -74,7 +76,10 @@ public class Config { countdown, changeCountdown, lobbyMin, - lobbyMax; + lobbyMax, + seekerPingLevel1, + seekerPingLevel2, + seekerPingLevel3; public static void loadConfig() { @@ -143,7 +148,7 @@ public class Config { //Glow glowLength = Math.max(1,manager.getInt("glow.time")); glowStackable = manager.getBoolean("glow.stackable"); - glowEnabled = manager.getBoolean("glow.enabled"); + glowEnabled = manager.getBoolean("glow.enabled") && Version.atLeast("1.9"); //Lobby minPlayers = Math.max(2, manager.getInt("minPlayers")); @@ -153,6 +158,12 @@ public class Config { lobbyMax = manager.getInt("lobby.max"); lobbyCountdownEnabled = manager.getBoolean("lobby.enabled"); + //SeekerPing + seekerPing = manager.getBoolean("seekerPing.enabled"); + seekerPingLevel1 = manager.getInt("seekerPing.distances.level1"); + seekerPingLevel2 = manager.getInt("seekerPing.distances.level2"); + seekerPingLevel3 = manager.getInt("seekerPing.distances.level3"); + //Other nametagsVisible = manager.getBoolean("nametagsVisible"); permissionsRequired = manager.getBoolean("permissionsRequired"); @@ -160,7 +171,7 @@ public class Config { pvpEnabled = manager.getBoolean("pvp"); autoJoin = manager.getBoolean("autoJoin"); teleportToExit = manager.getBoolean("teleportToExit"); - local = manager.getString("local"); + locale = manager.getString("locale", "local"); } public static void addToConfig(String path, Object value) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 84ad5b4..2217273 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -130,6 +130,20 @@ public class ConfigManager { } } + public String getString(String path, String oldPath){ + String value = config.getString(path); + if(value == null){ + String oldValue = config.getString(oldPath); + if(oldValue == null){ + return defaultConfig.getString(path); + } else { + return oldValue; + } + } else { + return value; + } + } + public void reset(String path){ config.set(path, defaultConfig.get(path)); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 569cae6..99bc74c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -19,9 +19,13 @@ package net.tylermurphy.hideAndSeek.configuration; +import com.cryptomorin.xseries.XEnchantment; +import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XPotion; +import net.tylermurphy.hideAndSeek.util.Version; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -63,7 +67,6 @@ public class Items { if(item != null) HIDER_ITEMS.add(item); i++; } - SEEKER_EFFECTS = new ArrayList<>(); ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker"); i = 1; @@ -91,18 +94,22 @@ public class Items { private static ItemStack createItem(ConfigurationSection item) { String material_string = item.getString("material"); if(material_string == null) return null; - Material material = Material.valueOf(material_string.toUpperCase()); + if(!XMaterial.matchXMaterial(material_string.toUpperCase()).isPresent()) return null; + Material material = XMaterial.matchXMaterial(material_string.toUpperCase()).get().parseMaterial(); int amount = item.getInt("amount"); + if(material == null) return null; ItemStack stack = new ItemStack(material, amount); - if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ + if(material == XMaterial.POTION.parseMaterial() || material == XMaterial.SPLASH_POTION.parseMaterial() || material == XMaterial.LINGERING_POTION.parseMaterial()){ PotionMeta meta = getPotionMeta(stack, item); + if(meta == null) return null; stack.setItemMeta(meta); } else { ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); if (enchantments != null) for (String enchantment_string : enchantments.getKeys(false)) { - Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantment_string)); + if(!XEnchantment.matchXEnchantment(enchantment_string).isPresent()) continue; + Enchantment enchantment = XEnchantment.matchXEnchantment(enchantment_string).get().getEnchant(); if (enchantment == null) continue; stack.addUnsafeEnchantment( enchantment, @@ -121,23 +128,38 @@ public class Items { String name = item.getString("name"); if(name != null) meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); - meta.setUnbreakable(item.getBoolean("unbreakable")); + if(Version.atLeast("1.11")){ + meta.setUnbreakable(item.getBoolean("unbreakable")); + } else { + meta.spigot().setUnbreakable(true); + } meta.setLore(item.getStringList("lore")); return meta; } - private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item){ + private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item) { String type = item.getString("type"); PotionMeta meta = (PotionMeta) stack.getItemMeta(); if(type==null) return meta; assert meta != null; - meta.setBasePotionData(new PotionData((PotionType.valueOf(type.toUpperCase())))); + XPotion.Effect potionEffect = XPotion.parseEffect(type.toUpperCase()); + if(potionEffect == null) return null; + XPotion xpotion = potionEffect.getXPotion(); + if(xpotion == null) return null; + PotionEffectType potionType = xpotion.getPotionEffectType(); + if(potionType == null) return null; + if(Version.atLeast("1.9")) { + meta.setBasePotionData(new PotionData(xpotion.getPotionType())); + } else { + meta.setMainEffect(potionType); + } return meta; } private static PotionEffect getPotionEffect(ConfigurationSection item){ String type = item.getString("type"); if(type == null) return null; + if(PotionEffectType.getByName(type.toUpperCase()) == null) return null; return new PotionEffect( Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())), item.getInt("duration"), diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index d5ae01d..5ea9e53 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -33,7 +33,7 @@ public class Localization { public static void loadLocalization() { - ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.local+".yml"); + ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.locale +".yml"); int PLUGIN_VERSION = 2; int VERSION = manager.getInt("version"); @@ -50,8 +50,8 @@ public class Localization { String SELECTED_LOCAL = manager.getString("type"); if(SELECTED_LOCAL == null){ manager.reset("type"); - } else if(!SELECTED_LOCAL.equals(Config.local)){ - manager.resetFile("lang"+File.separator+"localization_"+Config.local+".yml"); + } else if(!SELECTED_LOCAL.equals(Config.locale)){ + manager.resetFile("lang"+File.separator+"localization_"+Config.locale +".yml"); } manager.saveConfig(); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index 602c948..9a0837b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -68,6 +68,13 @@ public class Database { } public static void init(){ + try { + Class.forName("org.sqlite.JDBC"); + } catch (ClassNotFoundException e) { + Main.plugin.getLogger().severe("Unable to load SQLite driver!"); + System.exit(-1); + return; + } playerInfo = new PlayerInfoTable(); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 936f7ac..71060b9 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.stream.Collectors; import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -275,8 +276,13 @@ class CustomBoard { this.board = manager.getNewScoreboard(); this.LINES = new HashMap<>(); this.player = player; - this.obj = board.registerNewObjective( - "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); + if(Version.atLeast("1.13")){ + this.obj = board.registerNewObjective( + "Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title)); + } else { + this.obj = board.registerNewObjective("Scoreboard", "dummy"); + this.obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', title)); + } this.blanks = 0; this.displayed = false; this.updateTeams(); @@ -297,15 +303,30 @@ class CustomBoard { seekerTeam.removeEntry(entry); for(Player player : Board.getSeekers()) seekerTeam.addEntry(player.getName()); - if(nametagsVisible) { - hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); + if(Version.atLeast("1.9")){ + if(nametagsVisible) { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS); + } else { + hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + } } else { - hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + if(nametagsVisible) { + hiderTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); + seekerTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OWN_TEAM); + } else { + hiderTeam.setNameTagVisibility(NameTagVisibility.NEVER); + seekerTeam.setNameTagVisibility(NameTagVisibility.NEVER); + } + } + if(Version.atLeast("1.12")){ + hiderTeam.setColor(ChatColor.GOLD); + seekerTeam.setColor(ChatColor.RED); + } else { + hiderTeam.setPrefix(ChatColor.translateAlternateColorCodes('&', "&6")); + seekerTeam.setPrefix(ChatColor.translateAlternateColorCodes('&', "&c")); } - hiderTeam.setColor(ChatColor.GOLD); - seekerTeam.setColor(ChatColor.RED); } public void setLine(String key, String message){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 42589bc..10fc8db 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -21,8 +21,11 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XSound; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; @@ -178,16 +181,23 @@ public class EventListener implements Listener { } } } - if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) { + if (player.getHealth() - event.getFinalDamage() < 0 || !pvpEnabled) { if (spawnPosition == null) return; event.setCancelled(true); - AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); - if(attribute != null) - player.setHealth(attribute.getValue()); + if(Version.atLeast("1.9")) { + AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + if (attribute != null) player.setHealth(attribute.getValue()); + } else { + player.setHealth(player.getMaxHealth()); + } player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); - Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1); + if(Version.atLeast("1.9")){ + XSound.ENTITY_PLAYER_DEATH.play(player, 1, 1); + } else { + XSound.ENTITY_PLAYER_HURT.play(player, 1, 1); + } if (Board.isSeeker(player)) { - Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString()); + Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString()); } if (Board.isHider(player)) { if (attacker == null) { @@ -217,7 +227,8 @@ public class EventListener implements Listener { if(Board.isHider(player)) { Game.glow.onProjectile(); snowball.remove(); - player.getInventory().remove(Material.SNOWBALL); + assert XMaterial.SNOWBALL.parseMaterial() != null; + player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial()); } } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 225eab0..3b1a0dd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -21,14 +21,19 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XSound; +import com.cryptomorin.xseries.messages.Titles; import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.util.Status; +import net.tylermurphy.hideAndSeek.util.Version; import net.tylermurphy.hideAndSeek.util.WinType; import net.tylermurphy.hideAndSeek.world.WorldLoader; import org.bukkit.*; import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; @@ -42,7 +47,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.beans.EventHandler; import java.io.File; import java.util.*; import java.util.stream.Collectors; @@ -92,11 +96,11 @@ public class Game { for(Player player : Board.getSeekers()) { player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); - player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20); + Titles.sendTitle(player, 10, 70, 20, ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString()); } for(Player player : Board.getHiders()) { player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); - player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); + Titles.sendTitle(player, 10, 70, 20, ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString()); } if(tauntEnabled) taunt = new Taunt(); @@ -153,8 +157,10 @@ public class Game { player.removePotionEffect(effect.getType()); } player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100)); - for(Player temp : Board.getPlayers()) { - Packet.setGlow(player, temp, false); + if(Version.atLeast("1.9")){ + for(Player temp : Board.getPlayers()) { + Packet.setGlow(player, temp, false); + } } } EventListener.temp_loc.clear(); @@ -207,7 +213,8 @@ public class Game { for(PotionEffect effect : Items.HIDER_EFFECTS) player.addPotionEffect(effect); if(glowEnabled) { - ItemStack snowball = new ItemStack(Material.SNOWBALL, 1); + assert XMaterial.SNOWBALL.parseMaterial() != null; + ItemStack snowball = new ItemStack(XMaterial.SNOWBALL.parseMaterial(), 1); ItemMeta snowballMeta = snowball.getItemMeta(); assert snowballMeta != null; snowballMeta.setDisplayName("Glow Powerup"); @@ -238,11 +245,16 @@ public class Game { player.setGameMode(GameMode.SPECTATOR); Board.createGameBoard(player); player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - player.sendTitle(ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString(), 10, 70, 20); + Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString()); } player.setFoodLevel(20); - player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue()); + if(Version.atLeast("1.9")) { + AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); + if (attribute != null) player.setHealth(attribute.getValue()); + } else { + player.setHealth(player.getMaxHealth()); + } } public static void removeItems(Player player){ @@ -296,20 +308,36 @@ public class Game { distance = temp; } } - switch(tick%10) { +// if(seekerPing) switch(tick%10) { +// case 0: +// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .5f, 1f); +// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); +// break; +// case 3: +// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .3f, 1f); +// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); +// break; +// case 6: +// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); +// break; +// case 9: +// if(distance < seekerPingLevel2) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); +// break; +// } + if(seekerPing) switch(tick%10) { case 0: - if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f); - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .5f, 1f); + if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); break; case 3: - if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f); - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .3f, 1f); + if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); break; case 6: - if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); break; case 9: - if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f); + if(distance < seekerPingLevel2) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); break; } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index 18913da..d793f46 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -21,6 +21,8 @@ package net.tylermurphy.hideAndSeek.util; import java.lang.reflect.InvocationTargetException; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.protocollib.WrapperPlayServerNamedSoundEffect; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -38,19 +40,15 @@ public class Packet { private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); 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(); - } + WrapperPlayServerNamedSoundEffect packet = new WrapperPlayServerNamedSoundEffect(); + packet.setSoundCategory(SoundCategory.MASTER); + packet.setSoundEffect(sound); + packet.setEffectPositionX((int)(player.getLocation().getX() * 8.0)); + packet.setEffectPositionY((int)(player.getLocation().getY() * 8.0)); + packet.setEffectPositionZ((int)(player.getLocation().getZ() * 8.0)); + packet.setPitch(pitch); + packet.setVolume(volume); + packet.sendPacket(player); } public static void setGlow(Player player, Player target, boolean glowing) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Version.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Version.java new file mode 100644 index 0000000..96854db --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Version.java @@ -0,0 +1,45 @@ +package net.tylermurphy.hideAndSeek.util; + +import org.bukkit.Bukkit; + +import java.util.HashMap; +import java.util.Map; + +public class Version { + + private static final Map CACHE = new HashMap<>(); + + public static boolean atLeast(String testVersion){ + + + if(CACHE.containsKey(testVersion)) return CACHE.get(testVersion); + + String[] serverCheckTemp = Bukkit.getBukkitVersion().substring(2,Bukkit.getBukkitVersion().indexOf('-')).split("\\."); + int[] serverCheck = new int[serverCheckTemp.length]; + for(int i=0; i serverCheck[0]) return false; + else if(customCheck[0] < serverCheck[0]) return true; + else { + if (customCheck.length == 1 && serverCheck.length == 1) return true; + else if(customCheck.length == 2 && serverCheck.length == 2){ + return customCheck[1] <= serverCheck[1]; + } + else return serverCheck.length == 2; + } + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java new file mode 100644 index 0000000..f6bd15a --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java @@ -0,0 +1,115 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.tylermurphy.hideAndSeek.util.protocollib; + +import java.lang.reflect.InvocationTargetException; + +import org.bukkit.entity.Player; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.google.common.base.Objects; + +public abstract class AbstractPacket { + // The packet we will be modifying + protected PacketContainer handle; + + /** + * Constructs a new strongly typed wrapper for the given packet. + * + * @param handle - handle to the raw packet data. + * @param type - the packet type. + */ + protected AbstractPacket(PacketContainer handle, PacketType type) { + // Make sure we're given a valid packet + if (handle == null) + throw new IllegalArgumentException("Packet handle cannot be NULL."); + if (!Objects.equal(handle.getType(), type)) + throw new IllegalArgumentException(handle.getHandle() + + " is not a packet of type " + type); + + this.handle = handle; + } + + /** + * Retrieve a handle to the raw packet data. + * + * @return Raw packet data. + */ + public PacketContainer getHandle() { + return handle; + } + + /** + * Send the current packet to the given receiver. + * + * @param receiver - the receiver. + * @throws RuntimeException If the packet cannot be sent. + */ + public void sendPacket(Player receiver) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, + getHandle()); + } catch (InvocationTargetException e) { + throw new RuntimeException("Cannot send packet.", e); + } + } + + /** + * Send the current packet to all online players. + */ + public void broadcastPacket() { + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException If the packet cannot be received. + * @deprecated Misspelled. recieve to receive + * @see #receivePacket(Player) + */ + @Deprecated + public void recievePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot recieve packet.", e); + } + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException if the packet cannot be received. + */ + public void receivePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot receive packet.", e); + } + } +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java new file mode 100644 index 0000000..5851a75 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java @@ -0,0 +1,158 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.tylermurphy.hideAndSeek.util.protocollib; + +import org.bukkit.Sound; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; + +public class WrapperPlayServerNamedSoundEffect extends AbstractPacket { + public static final PacketType TYPE = + PacketType.Play.Server.NAMED_SOUND_EFFECT; + + public WrapperPlayServerNamedSoundEffect() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerNamedSoundEffect(PacketContainer packet) { + super(packet, TYPE); + } + + public Sound getSoundEffect() { + return handle.getSoundEffects().read(0); + } + + public void setSoundEffect(Sound value) { + handle.getSoundEffects().write(0, value); + } + + public SoundCategory getSoundCategory() { + return handle.getSoundCategories().read(0); + } + + public void setSoundCategory(SoundCategory value) { + handle.getSoundCategories().write(0, value); + } + + /** + * Retrieve Effect position X. + *

+ * Notes: effect X multiplied by 8 + * + * @return The current Effect position X + */ + public int getEffectPositionX() { + return handle.getIntegers().read(0); + } + + /** + * Set Effect position X. + * + * @param value - new value. + */ + public void setEffectPositionX(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Effect position Y. + *

+ * Notes: effect Y multiplied by 8 + * + * @return The current Effect position Y + */ + public int getEffectPositionY() { + return handle.getIntegers().read(1); + } + + /** + * Set Effect position Y. + * + * @param value - new value. + */ + public void setEffectPositionY(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Effect position Z. + *

+ * Notes: effect Z multiplied by 8 + * + * @return The current Effect position Z + */ + public int getEffectPositionZ() { + return handle.getIntegers().read(2); + } + + /** + * Set Effect position Z. + * + * @param value - new value. + */ + public void setEffectPositionZ(int value) { + handle.getIntegers().write(2, value); + } + + /** + * Retrieve Volume. + *

+ * Notes: 1 is 100%, can be more + * + * @return The current Volume + */ + public float getVolume() { + return handle.getFloat().read(0); + } + + /** + * Set Volume. + * + * @param value - new value. + */ + public void setVolume(float value) { + handle.getFloat().write(0, value); + } + + /** + * Retrieve Pitch. + *

+ * Notes: 63 is 100%, can be more + * + * @return The current Pitch + */ + public float getPitch() { + return handle.getFloat().read(1); + } + + /** + * Set Pitch. + * + * @param value - new value. + */ + public void setPitch(float value) { + handle.getFloat().write(1, value); + } + +} + diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 5d6e377..011d334 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -63,7 +64,7 @@ public class WorldLoader { } public void loadMap(){ - Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); + Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); World world = Bukkit.getServer().getWorld(savename); if(world == null){ Main.plugin.getLogger().severe("COULD NOT LOAD " + savename); @@ -111,7 +112,10 @@ public class WorldLoader { private void copyFileFolder(String name, Boolean isMca) throws IOException { File region = new File(Main.root+File.separator+mapname+File.separator+name); File temp = new File(Main.root+File.separator+"temp_"+savename+File.separator+name); + System.out.println(region.getAbsolutePath()); + System.out.println(temp.getAbsolutePath()); if(region.exists() && region.isDirectory()) { + System.out.println("passed"); if(!temp.exists()) if(!temp.mkdirs()) throw new IOException("Couldn't create region directory!"); @@ -121,17 +125,17 @@ public class WorldLoader { return; } for (String file : files) { - + System.out.println("Testing file "+ file); if(isMca) { - int minX = (int)Math.floor(saveMinX / 32.0); - int minZ = (int)Math.floor(saveMinZ / 32.0); - int maxX = (int)Math.floor(saveMaxX / 32.0); - int maxZ = (int)Math.floor(saveMaxZ / 32.0); + int minX = (int)Math.floor(saveMinX / 512.0); + int minZ = (int)Math.floor(saveMinZ / 512.0); + int maxX = (int)Math.floor(saveMaxX / 512.0); + int maxZ = (int)Math.floor(saveMaxZ / 512.0); String[] parts = file.split("\\."); if(parts.length > 1) { Main.plugin.getLogger().info(file); - if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX ||Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ ) + if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX || Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ ) continue; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 778e3b4..1e3cbda 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -90,10 +90,20 @@ lobby: max: 10 enabled: true +# As a hider, the closer a seeker gets to you, the louder and faster a pining noise will play. +# There are 3 separate distances (in blocks) you can set to the 3 different levels for the noise. +# The higher the level, the closer the seeker. +seekerPing: + distances: + level1: 30 + level2: 20 + level3: 10 + enabled: true + # Changes the default plugin language. Currently, Supported localizations are: # en-US (English - United States) # de-DE (German - Germany) -local: "en-US" +locale: "en-US" # ---------------------------------------------------------- # # ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index bd391c9..c03205c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,9 @@ name: HideAndSeek main: net.tylermurphy.hideAndSeek.Main -version: 1.3.3 +version: 1.4.0 author: KenshinEto load: STARTUP -api-version: 1.14 +api-version: 1.13 depend: [ProtocolLib] commands: hideandseek: @@ -29,6 +29,8 @@ permissions: hideandseek.join: true hideandseek.leave: true hideandseek.leavebounds: true + hideandseek.wins: true + hideand.top: true hideandseek.about: description: Allows you to run the about command default: true @@ -74,3 +76,9 @@ permissions: hideandseek.leavebounds: description: Allows players to leave specified game bounderies default: op + hideandseek.wins: + description: Allows players to see a players amount of wins + default: true + hideandseek.top: + description: Allows players to see the global wins leaderboard + default: true From 8a011945d6e68b8e8dd44c247e66da3b3895199e Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Apr 2022 12:38:03 -0400 Subject: [PATCH 2/7] pom fix --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d029bea..2ca8916 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ org.spigotmc spigot-api - 1.9-R0.1-SNAPSHOT + 1.13-R0.1-SNAPSHOT jar provided From a812bde64c2349deccf45778e746d0b614fa48c3 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Apr 2022 16:02:47 -0400 Subject: [PATCH 3/7] potions work in 1.8, fixed death catch system --- .../hideAndSeek/configuration/Items.java | 92 +++++-------------- .../hideAndSeek/game/EventListener.java | 2 +- 2 files changed, 25 insertions(+), 69 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index 99bc74c..1c77ec2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -19,18 +19,12 @@ package net.tylermurphy.hideAndSeek.configuration; -import com.cryptomorin.xseries.XEnchantment; -import com.cryptomorin.xseries.XMaterial; -import com.cryptomorin.xseries.XPotion; +import com.cryptomorin.xseries.XItemStack; import net.tylermurphy.hideAndSeek.util.Version; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.enchantments.Enchantment; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.*; import java.util.ArrayList; @@ -92,70 +86,32 @@ public class Items { } private static ItemStack createItem(ConfigurationSection item) { - String material_string = item.getString("material"); - if(material_string == null) return null; - if(!XMaterial.matchXMaterial(material_string.toUpperCase()).isPresent()) return null; - Material material = XMaterial.matchXMaterial(material_string.toUpperCase()).get().parseMaterial(); - int amount = item.getInt("amount"); - if(material == null) return null; - ItemStack stack = new ItemStack(material, amount); - if(material == XMaterial.POTION.parseMaterial() || material == XMaterial.SPLASH_POTION.parseMaterial() || material == XMaterial.LINGERING_POTION.parseMaterial()){ - PotionMeta meta = getPotionMeta(stack, item); - if(meta == null) return null; - stack.setItemMeta(meta); - - } else { - ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); - if (enchantments != null) - for (String enchantment_string : enchantments.getKeys(false)) { - if(!XEnchantment.matchXEnchantment(enchantment_string).isPresent()) continue; - Enchantment enchantment = XEnchantment.matchXEnchantment(enchantment_string).get().getEnchant(); - if (enchantment == null) continue; - stack.addUnsafeEnchantment( - enchantment, - enchantments.getInt(enchantment_string) - ); - } - ItemMeta meta = getItemMeta(stack,item); - stack.setItemMeta(meta); + ConfigurationSection config = new YamlConfiguration().createSection("temp"); + String material = item.getString("material").toUpperCase(); + boolean splash = false; + if(!Version.atLeast("1.9")){ + if(material.contains("POTION")){ + config.set("level", 1); + } + if(material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")){ + material = "POTION"; + splash = true; + } } + config.set("name", item.getString("name")); + config.set("material", material); + config.set("enchants", item.getConfigurationSection("enchantments")); + config.set("unbreakable", item.getBoolean("unbreakable")); + if(item.isSet("lore")) + config.set("lore", item.getStringList("lore")); + if (material.equalsIgnoreCase("POTION") || material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) + config.set("base-effect", String.format("%s,%s,%s", item.getString("type"), false, splash)); + ItemStack stack = XItemStack.deserialize(config); + stack.setAmount(item.getInt("amount")); + if(stack.getData().getItemType() == Material.AIR) return null; return stack; } - private static ItemMeta getItemMeta(ItemStack stack, ConfigurationSection item){ - ItemMeta meta = stack.getItemMeta(); - assert meta != null; - String name = item.getString("name"); - if(name != null) - meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); - if(Version.atLeast("1.11")){ - meta.setUnbreakable(item.getBoolean("unbreakable")); - } else { - meta.spigot().setUnbreakable(true); - } - meta.setLore(item.getStringList("lore")); - return meta; - } - - private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item) { - String type = item.getString("type"); - PotionMeta meta = (PotionMeta) stack.getItemMeta(); - if(type==null) return meta; - assert meta != null; - XPotion.Effect potionEffect = XPotion.parseEffect(type.toUpperCase()); - if(potionEffect == null) return null; - XPotion xpotion = potionEffect.getXPotion(); - if(xpotion == null) return null; - PotionEffectType potionType = xpotion.getPotionEffectType(); - if(potionType == null) return null; - if(Version.atLeast("1.9")) { - meta.setBasePotionData(new PotionData(xpotion.getPotionType())); - } else { - meta.setMainEffect(potionType); - } - return meta; - } - private static PotionEffect getPotionEffect(ConfigurationSection item){ String type = item.getString("type"); if(type == null) return null; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 10fc8db..9271e5c 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -181,7 +181,7 @@ public class EventListener implements Listener { } } } - if (player.getHealth() - event.getFinalDamage() < 0 || !pvpEnabled) { + if (player.getHealth() - event.getFinalDamage() < 0.5 || !pvpEnabled) { if (spawnPosition == null) return; event.setCancelled(true); if(Version.atLeast("1.9")) { From ec2bf9d35d96ecb85a4d836d17f01cf6922c3f4c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 11 Apr 2022 17:23:50 -0400 Subject: [PATCH 4/7] 1.4.0 rc1 --- .../tylermurphy/hideAndSeek/util/Packet.java | 16 -- .../util/protocollib/AbstractPacket.java | 115 ------------- .../WrapperPlayServerNamedSoundEffect.java | 158 ------------------ 3 files changed, 289 deletions(-) delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java delete mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java index d793f46..9cb17ce 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Packet.java @@ -21,9 +21,6 @@ package net.tylermurphy.hideAndSeek.util; import java.lang.reflect.InvocationTargetException; -import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.util.protocollib.WrapperPlayServerNamedSoundEffect; -import org.bukkit.Sound; import org.bukkit.entity.Player; import com.comphenix.protocol.PacketType; @@ -31,25 +28,12 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; public class Packet { private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); - - public static void playSound(Player player, Sound sound, float volume, float pitch) { - WrapperPlayServerNamedSoundEffect packet = new WrapperPlayServerNamedSoundEffect(); - packet.setSoundCategory(SoundCategory.MASTER); - packet.setSoundEffect(sound); - packet.setEffectPositionX((int)(player.getLocation().getX() * 8.0)); - packet.setEffectPositionY((int)(player.getLocation().getY() * 8.0)); - packet.setEffectPositionZ((int)(player.getLocation().getZ() * 8.0)); - packet.setPitch(pitch); - packet.setVolume(volume); - packet.sendPacket(player); - } public static void setGlow(Player player, Player target, boolean glowing) { PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java deleted file mode 100644 index f6bd15a..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/AbstractPacket.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * PacketWrapper - ProtocolLib wrappers for Minecraft packets - * Copyright (C) dmulloy2 - * Copyright (C) Kristian S. Strangeland - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.tylermurphy.hideAndSeek.util.protocollib; - -import java.lang.reflect.InvocationTargetException; - -import org.bukkit.entity.Player; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketContainer; -import com.google.common.base.Objects; - -public abstract class AbstractPacket { - // The packet we will be modifying - protected PacketContainer handle; - - /** - * Constructs a new strongly typed wrapper for the given packet. - * - * @param handle - handle to the raw packet data. - * @param type - the packet type. - */ - protected AbstractPacket(PacketContainer handle, PacketType type) { - // Make sure we're given a valid packet - if (handle == null) - throw new IllegalArgumentException("Packet handle cannot be NULL."); - if (!Objects.equal(handle.getType(), type)) - throw new IllegalArgumentException(handle.getHandle() - + " is not a packet of type " + type); - - this.handle = handle; - } - - /** - * Retrieve a handle to the raw packet data. - * - * @return Raw packet data. - */ - public PacketContainer getHandle() { - return handle; - } - - /** - * Send the current packet to the given receiver. - * - * @param receiver - the receiver. - * @throws RuntimeException If the packet cannot be sent. - */ - public void sendPacket(Player receiver) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, - getHandle()); - } catch (InvocationTargetException e) { - throw new RuntimeException("Cannot send packet.", e); - } - } - - /** - * Send the current packet to all online players. - */ - public void broadcastPacket() { - ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle()); - } - - /** - * Simulate receiving the current packet from the given sender. - * - * @param sender - the sender. - * @throws RuntimeException If the packet cannot be received. - * @deprecated Misspelled. recieve to receive - * @see #receivePacket(Player) - */ - @Deprecated - public void recievePacket(Player sender) { - try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, - getHandle()); - } catch (Exception e) { - throw new RuntimeException("Cannot recieve packet.", e); - } - } - - /** - * Simulate receiving the current packet from the given sender. - * - * @param sender - the sender. - * @throws RuntimeException if the packet cannot be received. - */ - public void receivePacket(Player sender) { - try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, - getHandle()); - } catch (Exception e) { - throw new RuntimeException("Cannot receive packet.", e); - } - } -} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java b/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java deleted file mode 100644 index 5851a75..0000000 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/protocollib/WrapperPlayServerNamedSoundEffect.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * PacketWrapper - ProtocolLib wrappers for Minecraft packets - * Copyright (C) dmulloy2 - * Copyright (C) Kristian S. Strangeland - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.tylermurphy.hideAndSeek.util.protocollib; - -import org.bukkit.Sound; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory; - -public class WrapperPlayServerNamedSoundEffect extends AbstractPacket { - public static final PacketType TYPE = - PacketType.Play.Server.NAMED_SOUND_EFFECT; - - public WrapperPlayServerNamedSoundEffect() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerNamedSoundEffect(PacketContainer packet) { - super(packet, TYPE); - } - - public Sound getSoundEffect() { - return handle.getSoundEffects().read(0); - } - - public void setSoundEffect(Sound value) { - handle.getSoundEffects().write(0, value); - } - - public SoundCategory getSoundCategory() { - return handle.getSoundCategories().read(0); - } - - public void setSoundCategory(SoundCategory value) { - handle.getSoundCategories().write(0, value); - } - - /** - * Retrieve Effect position X. - *

- * Notes: effect X multiplied by 8 - * - * @return The current Effect position X - */ - public int getEffectPositionX() { - return handle.getIntegers().read(0); - } - - /** - * Set Effect position X. - * - * @param value - new value. - */ - public void setEffectPositionX(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve Effect position Y. - *

- * Notes: effect Y multiplied by 8 - * - * @return The current Effect position Y - */ - public int getEffectPositionY() { - return handle.getIntegers().read(1); - } - - /** - * Set Effect position Y. - * - * @param value - new value. - */ - public void setEffectPositionY(int value) { - handle.getIntegers().write(1, value); - } - - /** - * Retrieve Effect position Z. - *

- * Notes: effect Z multiplied by 8 - * - * @return The current Effect position Z - */ - public int getEffectPositionZ() { - return handle.getIntegers().read(2); - } - - /** - * Set Effect position Z. - * - * @param value - new value. - */ - public void setEffectPositionZ(int value) { - handle.getIntegers().write(2, value); - } - - /** - * Retrieve Volume. - *

- * Notes: 1 is 100%, can be more - * - * @return The current Volume - */ - public float getVolume() { - return handle.getFloat().read(0); - } - - /** - * Set Volume. - * - * @param value - new value. - */ - public void setVolume(float value) { - handle.getFloat().write(0, value); - } - - /** - * Retrieve Pitch. - *

- * Notes: 63 is 100%, can be more - * - * @return The current Pitch - */ - public float getPitch() { - return handle.getFloat().read(1); - } - - /** - * Set Pitch. - * - * @param value - new value. - */ - public void setPitch(float value) { - handle.getFloat().write(1, value); - } - -} - From 38fd4f57406c428b5feb343edfb41945774b4cf4 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 12 Apr 2022 15:11:49 -0400 Subject: [PATCH 5/7] added custom leaderboard, bug fixes --- .../hideAndSeek/configuration/Config.java | 161 +++++++++++------- .../configuration/ConfigManager.java | 14 ++ .../configuration/Localization.java | 9 +- .../tylermurphy/hideAndSeek/game/Board.java | 118 +++++++------ .../hideAndSeek/game/EventListener.java | 8 + .../tylermurphy/hideAndSeek/game/Game.java | 34 +--- src/main/resources/config.yml | 26 ++- .../resources/lang/localization_de-DE.yml | 1 + .../resources/lang/localization_en-US.yml | 7 +- src/main/resources/leaderboard.yml | 87 ++++++++++ 10 files changed, 326 insertions(+), 139 deletions(-) create mode 100644 src/main/resources/leaderboard.yml diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 98b27b2..5213f5d 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -22,9 +22,12 @@ package net.tylermurphy.hideAndSeek.configuration; import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.util.Vector; +import java.util.Collections; +import java.util.List; + public class Config { - private static ConfigManager manager; + private static ConfigManager config, leaderboard; public static String messagePrefix, @@ -80,106 +83,148 @@ public class Config { seekerPingLevel1, seekerPingLevel2, seekerPingLevel3; + + public static String + LOBBY_TITLE, + GAME_TITLE, + COUNTDOWN_WAITING, + COUNTDOWN_COUNTING, + COUNTDOWN_ADMINSTART, + TAUNT_COUNTING, + TAUNT_ACTIVE, + TAUNT_EXPIRED, + GLOW_ACTIVE, + GLOW_INACTIVE, + BORDER_COUNTING, + BORDER_DECREASING; + + public static List + LOBBY_CONTENTS, + GAME_CONTENTS; + + public static List + blockedCommands; public static void loadConfig() { - manager = new ConfigManager("config.yml"); - manager.saveConfig(); + config = new ConfigManager("config.yml"); + config.saveConfig(); + leaderboard = new ConfigManager("leaderboard.yml"); + leaderboard.saveConfig(); //Spawn spawnPosition = new Vector( - manager.getDouble("spawns.game.x"), - Math.max(0, Math.min(255, manager.getDouble("spawns.game.y"))), - manager.getDouble("spawns.game.z") + config.getDouble("spawns.game.x"), + Math.max(0, Math.min(255, config.getDouble("spawns.game.y"))), + config.getDouble("spawns.game.z") ); - spawnWorld = manager.getString("spawns.game.world"); + spawnWorld = config.getString("spawns.game.world"); ///Lobby lobbyPosition = new Vector( - manager.getDouble("spawns.lobby.x"), - Math.max(0, Math.min(255, manager.getDouble("spawns.lobby.y"))), - manager.getDouble("spawns.lobby.z") + config.getDouble("spawns.lobby.x"), + Math.max(0, Math.min(255, config.getDouble("spawns.lobby.y"))), + config.getDouble("spawns.lobby.z") ); - lobbyWorld = manager.getString("spawns.lobby.world"); + lobbyWorld = config.getString("spawns.lobby.world"); - announceMessagesToNonPlayers = manager.getBoolean("announceMessagesToNonPlayers"); + announceMessagesToNonPlayers = config.getBoolean("announceMessagesToNonPlayers"); exitPosition = new Vector( - manager.getDouble("spawns.exit.x"), - Math.max(0, Math.min(255, manager.getDouble("spawns.exit.y"))), - manager.getDouble("spawns.exit.z") + config.getDouble("spawns.exit.x"), + Math.max(0, Math.min(255, config.getDouble("spawns.exit.y"))), + config.getDouble("spawns.exit.z") ); - exitWorld = manager.getString("spawns.exit.world"); + exitWorld = config.getString("spawns.exit.world"); //World border worldborderPosition = new Vector( - manager.getInt("worldBorder.x"), + config.getInt("worldBorder.x"), 0, - manager.getInt("worldBorder.z") + config.getInt("worldBorder.z") ); - worldborderSize = Math.max(100, manager.getInt("worldBorder.size")); - worldborderDelay = Math.max(1, manager.getInt("worldBorder.delay")); - worldborderEnabled = manager.getBoolean("worldBorder.enabled"); + worldborderSize = Math.max(100, config.getInt("worldBorder.size")); + worldborderDelay = Math.max(1, config.getInt("worldBorder.delay")); + worldborderEnabled = config.getBoolean("worldBorder.enabled"); //Prefix char SYMBOLE = '\u00A7'; String SYMBOLE_STRING = String.valueOf(SYMBOLE); - messagePrefix = manager.getString("prefix.default").replace("&", SYMBOLE_STRING); - errorPrefix = manager.getString("prefix.error").replace("&", SYMBOLE_STRING); - tauntPrefix = manager.getString("prefix.taunt").replace("&", SYMBOLE_STRING); - worldborderPrefix = manager.getString("prefix.border").replace("&", SYMBOLE_STRING); - abortPrefix = manager.getString("prefix.abort").replace("&", SYMBOLE_STRING); - gameoverPrefix = manager.getString("prefix.gameover").replace("&", SYMBOLE_STRING); - warningPrefix = manager.getString("prefix.warning").replace("&", SYMBOLE_STRING); + messagePrefix = config.getString("prefix.default").replace("&", SYMBOLE_STRING); + errorPrefix = config.getString("prefix.error").replace("&", SYMBOLE_STRING); + tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOLE_STRING); + worldborderPrefix = config.getString("prefix.border").replace("&", SYMBOLE_STRING); + abortPrefix = config.getString("prefix.abort").replace("&", SYMBOLE_STRING); + gameoverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING); + warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING); //Map Bounds - saveMinX = manager.getInt("bounds.min.x"); - saveMinZ = manager.getInt("bounds.min.z"); - saveMaxX = manager.getInt("bounds.max.x"); - saveMaxZ = manager.getInt("bounds.max.z"); + saveMinX = config.getInt("bounds.min.x"); + saveMinZ = config.getInt("bounds.min.z"); + saveMaxX = config.getInt("bounds.max.x"); + saveMaxZ = config.getInt("bounds.max.z"); //Taunt - tauntEnabled = manager.getBoolean("taunt.enabled"); - tauntCountdown = manager.getBoolean("taunt.showCountdown"); - tauntDelay = Math.max(60,manager.getInt("taunt.delay")); - tauntLast = manager.getBoolean("taunt.whenLastPerson"); + tauntEnabled = config.getBoolean("taunt.enabled"); + tauntCountdown = config.getBoolean("taunt.showCountdown"); + tauntDelay = Math.max(60, config.getInt("taunt.delay")); + tauntLast = config.getBoolean("taunt.whenLastPerson"); //Glow - glowLength = Math.max(1,manager.getInt("glow.time")); - glowStackable = manager.getBoolean("glow.stackable"); - glowEnabled = manager.getBoolean("glow.enabled") && Version.atLeast("1.9"); + glowLength = Math.max(1, config.getInt("glow.time")); + glowStackable = config.getBoolean("glow.stackable"); + glowEnabled = config.getBoolean("glow.enabled") && Version.atLeast("1.9"); //Lobby - minPlayers = Math.max(2, manager.getInt("minPlayers")); - countdown = Math.max(10,manager.getInt("lobby.countdown")); - changeCountdown = Math.max(minPlayers,manager.getInt("lobby.changeCountdown")); - lobbyMin = Math.max(minPlayers,manager.getInt("lobby.min")); - lobbyMax = manager.getInt("lobby.max"); - lobbyCountdownEnabled = manager.getBoolean("lobby.enabled"); + minPlayers = Math.max(2, config.getInt("minPlayers")); + countdown = Math.max(10, config.getInt("lobby.countdown")); + changeCountdown = Math.max(minPlayers, config.getInt("lobby.changeCountdown")); + lobbyMin = Math.max(minPlayers, config.getInt("lobby.min")); + lobbyMax = config.getInt("lobby.max"); + lobbyCountdownEnabled = config.getBoolean("lobby.enabled"); //SeekerPing - seekerPing = manager.getBoolean("seekerPing.enabled"); - seekerPingLevel1 = manager.getInt("seekerPing.distances.level1"); - seekerPingLevel2 = manager.getInt("seekerPing.distances.level2"); - seekerPingLevel3 = manager.getInt("seekerPing.distances.level3"); + seekerPing = config.getBoolean("seekerPing.enabled"); + seekerPingLevel1 = config.getInt("seekerPing.distances.level1"); + seekerPingLevel2 = config.getInt("seekerPing.distances.level2"); + seekerPingLevel3 = config.getInt("seekerPing.distances.level3"); //Other - nametagsVisible = manager.getBoolean("nametagsVisible"); - permissionsRequired = manager.getBoolean("permissionsRequired"); - gameLength = manager.getInt("gameLength"); - pvpEnabled = manager.getBoolean("pvp"); - autoJoin = manager.getBoolean("autoJoin"); - teleportToExit = manager.getBoolean("teleportToExit"); - locale = manager.getString("locale", "local"); + nametagsVisible = config.getBoolean("nametagsVisible"); + permissionsRequired = config.getBoolean("permissionsRequired"); + gameLength = config.getInt("gameLength"); + pvpEnabled = config.getBoolean("pvp"); + autoJoin = config.getBoolean("autoJoin"); + teleportToExit = config.getBoolean("teleportToExit"); + locale = config.getString("locale", "local"); + blockedCommands = config.getStringList("blockedCommands"); + + //Leaderboard + LOBBY_TITLE = leaderboard.getString("lobby.title"); + GAME_TITLE = leaderboard.getString("game.title"); + LOBBY_CONTENTS = leaderboard.getStringList("lobby.content"); + Collections.reverse(LOBBY_CONTENTS); + GAME_CONTENTS = leaderboard.getStringList("game.content"); + Collections.reverse(GAME_CONTENTS); + COUNTDOWN_WAITING = leaderboard.getString("countdown.waiting"); + COUNTDOWN_COUNTING = leaderboard.getString("countdown.counting"); + COUNTDOWN_ADMINSTART = leaderboard.getString("countdown.adminStart"); + TAUNT_COUNTING = leaderboard.getString("taunt.counting"); + TAUNT_ACTIVE = leaderboard.getString("taunt.active"); + TAUNT_EXPIRED = leaderboard.getString("taunt.expired"); + GLOW_ACTIVE = leaderboard.getString("glow.active"); + GLOW_INACTIVE = leaderboard.getString("glow.inactive"); + BORDER_COUNTING = leaderboard.getString("border.counting"); + BORDER_DECREASING = leaderboard.getString("border.decreasing"); } public static void addToConfig(String path, Object value) { - manager.set(path, value); + config.set(path, value); } public static void saveConfig() { - manager.saveConfig(); + config.saveConfig(); } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 2217273..66073cd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -26,6 +26,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.List; import java.util.Map; public class ConfigManager { @@ -121,6 +122,10 @@ public class ConfigManager { } } + public int getDefaultInt(String path){ + return defaultConfig.getInt(path); + } + public String getString(String path){ String value = config.getString(path); if(value == null){ @@ -144,6 +149,15 @@ public class ConfigManager { } } + public List getStringList(String path){ + List value = config.getStringList(path); + if(value == null){ + return defaultConfig.getStringList(path); + } else { + return value; + } + } + public void reset(String path){ config.set(path, defaultConfig.get(path)); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 5ea9e53..07402d1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -29,18 +29,21 @@ public class Localization { public static final Map LOCAL = new HashMap<>(); - private static final String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; + private static final Map CHANGES = new HashMap() {{ + put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"}}); + put("de-DE", new String[][]{{}}); + }}; public static void loadLocalization() { ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.locale +".yml"); - int PLUGIN_VERSION = 2; + int PLUGIN_VERSION = manager.getDefaultInt("version"); int VERSION = manager.getInt("version"); if(VERSION < PLUGIN_VERSION){ for(int i = VERSION; i < PLUGIN_VERSION; i++){ if(i < 1) continue; - String[] changeList = CHANGES[i-1]; + String[] changeList = CHANGES.get(Config.locale)[i-1]; for(String change : changeList) manager.reset("Localization." + change); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 71060b9..fd75040 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -21,10 +21,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import net.tylermurphy.hideAndSeek.util.Status; @@ -151,19 +148,28 @@ public class Board { board = new CustomBoard(player, "&l&eHIDE AND SEEK"); board.updateTeams(); } - board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER %" + ChatColor.WHITE + getHiderPercent()); - board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER %" + ChatColor.WHITE + getSeekerPercent()); - board.addBlank(); - board.setLine("players", "Players: " + playerList.values().size()); - board.addBlank(); - if(lobbyCountdownEnabled){ - if(Game.countdownTime == -1){ - board.setLine("waiting", "Waiting for players..."); + int i=0; + for(String line : LOBBY_CONTENTS){ + if(line.equalsIgnoreCase("")){ + board.addBlank(); + } else if(line.contains("{COUNTDOWN}")){ + if(!lobbyCountdownEnabled){ + board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_ADMINSTART)); + } else if(Game.countdownTime == -1){ + board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_WAITING)); + } else { + board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_COUNTING.replace("{AMOUNT}",Game.countdownTime+""))); + } + } else if(line.contains("{COUNT}")){ + board.setLine(String.valueOf(i), line.replace("{COUNT}", getPlayers().size()+"")); + } else if(line.contains("{SEEKER%}")){ + board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+"")); + } else if(line.contains("{HIDER%}")){ + board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+"")); } else { - board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Game.countdownTime+"s"); + board.setLine(String.valueOf(i), line); } - } else { - board.setLine("waiting", "Waiting for gamemaster..."); + i++; } board.display(); customBoards.put(player.getName(), board); @@ -176,42 +182,58 @@ public class Board { private static void createGameBoard(Player player, boolean recreate){ CustomBoard board = customBoards.get(player.getName()); if(recreate) { - board = new CustomBoard(player, "&l&eHIDE AND SEEK"); + board = new CustomBoard(player, GAME_TITLE); board.updateTeams(); } - board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size()); - board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size()); - board.addBlank(); - if(glowEnabled){ - if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) - board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive"); - else - board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active"); - } - if(tauntEnabled && tauntCountdown){ - if(Game.taunt == null || Game.status == Status.STARTING) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s"); - else if(!tauntLast && Hider.size() == 1){ - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired"); - } else if(!Game.taunt.isRunning()) - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Game.taunt.getDelay()/60 + "m" + Game.taunt.getDelay()%60 + "s"); - else - board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active"); - } - if(worldborderEnabled){ - if(Game.worldBorder == null || Game.status == Status.STARTING){ - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s"); - } else if(!Game.worldBorder.isRunning()) { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Game.worldBorder.getDelay()/60 + "m" + Game.worldBorder.getDelay()%60 + "s"); + + int i = 0; + for(String line : GAME_CONTENTS){ + if(line.equalsIgnoreCase("")){ + board.addBlank(); } else { - board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing"); + if(line.contains("{TIME}")) { + String value = Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s"; + board.setLine(String.valueOf(i), line.replace("{TIME}", value)); + } else if(line.contains("{TEAM}")) { + String value = getTeam(player); + board.setLine(String.valueOf(i), line.replace("{TEAM}", value)); + } else if(line.contains("{BORDER}")) { + if(!worldborderEnabled) continue; + if(Game.worldBorder == null || Game.status == Status.STARTING){ + board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0"))); + } else if(!Game.worldBorder.isRunning()) { + board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()%60+""))); + } else { + board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_DECREASING)); + } + } else if(line.contains("{TAUNT}")){ + if(!tauntEnabled) continue; + if(Game.taunt == null || Game.status == Status.STARTING) { + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replace("{AMOUNT}", "0"))); + } else if(!tauntLast && Hider.size() == 1){ + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_EXPIRED)); + } else if(!Game.taunt.isRunning()) { + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() / 60 + "").replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() % 60 + ""))); + } else { + board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_ACTIVE)); + } + } else if(line.contains("{GLOW}")){ + if(!glowEnabled) return; + if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) { + board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_INACTIVE)); + } else { + board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_ACTIVE)); + } + } else if(line.contains("{#SEEKER}")) { + board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+"")); + } else if(line.contains("{#HIDER}")) { + board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+"")); + } else { + board.setLine(String.valueOf(i), line); + } } + i++; } - if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled) - board.addBlank(); - board.setLine("time", "Time Left: " + ChatColor.GREEN + Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s"); - board.addBlank(); - board.setLine("team", "Team: " + getTeam(player)); board.display(); customBoards.put(player.getName(), board); } @@ -332,9 +354,9 @@ class CustomBoard { public void setLine(String key, String message){ Line line = LINES.get(key); if(line == null) - addLine(key, message); + addLine(key, ChatColor.translateAlternateColorCodes('&',message)); else - updateLine(key, message); + updateLine(key, ChatColor.translateAlternateColorCodes('&',message)); } private void addLine(String key, String message){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 9271e5c..698d650 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -271,5 +271,13 @@ public class EventListener implements Listener { } } } + for(String handle : blockedCommands){ + System.out.println(handle); + if(array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && Game.status != Status.STANDBY){ + player.sendMessage(errorPrefix + message("BLOCKED_COMMAND")); + event.setCancelled(true); + break; + } + } } } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index 3b1a0dd..a016a4e 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -96,6 +96,7 @@ public class Game { for(Player player : Board.getSeekers()) { player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,1000000,128,false,false)); Titles.sendTitle(player, 10, 70, 20, ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString()); } for(Player player : Board.getHiders()) { @@ -273,8 +274,10 @@ public class Game { countdownTime = countdown; if(Board.size() >= changeCountdown) countdownTime = Math.min(countdownTime, 10); - if(tick % 20 == 0) + if(tick % 20 == 0) { countdownTime--; + Board.reloadLobbyBoards(); + } if(countdownTime == 0){ Optional rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); if(!rand.isPresent()){ @@ -308,22 +311,6 @@ public class Game { distance = temp; } } -// if(seekerPing) switch(tick%10) { -// case 0: -// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .5f, 1f); -// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// case 3: -// if(distance < seekerPingLevel1) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_BASEDRUM.parseSound(), .3f, 1f); -// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// case 6: -// if(distance < seekerPingLevel3) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// case 9: -// if(distance < seekerPingLevel2) Packet.playSound(hider, XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), .3f, 1f); -// break; -// } if(seekerPing) switch(tick%10) { case 0: if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .5f, 1f); @@ -390,21 +377,18 @@ class Glow { public void onProjectile() { if(glowStackable) glowTime += glowLength; else glowTime = glowLength; - if(!running) - startGlow(); + running = true; } - private void startGlow() { - running = true; - for(Player hider : Board.getHiders()) { - for(Player seeker : Board.getSeekers()) { + private void sendPackets(){ + for(Player hider : Board.getHiders()) + for(Player seeker : Board.getSeekers()) Packet.setGlow(hider, seeker, true); - } - } } protected void update() { if(running) { + sendPackets(); glowTime--; glowTime = Math.max(glowTime, 0); if (glowTime == 0) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1e3cbda..0cb2517 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,11 @@ +#============================================================# +# +--------------------------------------------------------+ # +# | Kenshins Hide and Seek | # +# | Configuration file | # +# | by KenshinEto | # +# +--------------------------------------------------------+ # +#============================================================# + # How long in seconds will the game last, set it < 1 to disable # default: 1200 aka 20min gameLength: 1200 @@ -30,7 +38,7 @@ pvp: true autoJoin: false # (When autoJoin is false), when players join the world containing the lobby, they are automatically teleported -# to the designated exit position so that they possibly don't spawn in the lobby while not in the queue. Anyone +# to the designated exit position so that they don't spawn in the lobby while not in the queue. Anyone # who ever joins in the game world (the duplicated world where the game is played) will always be teleported # out regardless. # default: false @@ -105,13 +113,27 @@ seekerPing: # de-DE (German - Germany) locale: "en-US" +# Block's commands being run by any user while playing the game. +# Can be usefully If you aren't using a permission plugin and want +# to op people, but still want to block certain commands. +# Not really usefully if using permission plugins. +# You can add /kill for any use, but it's already blocked on those +# playing the game. +blockedCommands: + - msg + - tp + - gamemode + - kill + - give + - effect + # ---------------------------------------------------------- # # ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING # # ---------------------------------------------------------- # # The 2 coordinate bounds that will contain your hideAndSeek map. Its recommended # that you use /hs setbounds for this, and not edit this directly, as breaking -# this section will completely break the entire plugin when you run /hs mapsave. +# this section will completely break the entire plugin when you run /hs savemap. bounds: min: x: 0 diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index d2dcc1e..67c14fd 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -64,6 +64,7 @@ Localization: NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält." NO_GAME_INFO: "Keine Informationen zum Gameplay für diesen Spieler vorhanden." INFORMATION_FOR: "Gewinninformationen für {PLAYER}:" + BLOCKED_COMMAND: "Command blocked by Kenshin's Hide And Seek" # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE version: 2 diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 93cbd4e..16dacc8 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -37,7 +37,7 @@ Localization: WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." WORLDBORDER_WARN: "World border will shrink in the next 30s!" - TAUNTED: "$c$oOh no! You have been chosen to be taunted." + TAUNTED: "&c&oOh no! You have been chosen to be taunted." TAUNT: "A random hider will be taunted in the next 30s." TAUNT_ACTIVATE: "Taunt has been activated." ERROR_GAME_SPAWN: "Please set game spawn location first" @@ -54,7 +54,7 @@ Localization: START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start." START_INVALID_NAME: "Invalid player: {PLAYER}." START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!" - START: "Attention SEEKERS, its time to fin the hiders!" + START: "Attention SEEKERS, its time to find the hiders!" STOP: "Game has been force stopped." HIDERS_SUBTITLE: "Hide away from the seekers" SEEKERS_SUBTITLE: "Eliminate all hiders" @@ -64,7 +64,8 @@ Localization: NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." NO_GAME_INFO: "Player has no gameplay information." INFORMATION_FOR: "Win information for {PLAYER}:" + BLOCKED_COMMAND: "Command blocked by Hide And Seek plugin." # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE -version: 2 +version: 3 type: "en-US" \ No newline at end of file diff --git a/src/main/resources/leaderboard.yml b/src/main/resources/leaderboard.yml new file mode 100644 index 0000000..376ae9f --- /dev/null +++ b/src/main/resources/leaderboard.yml @@ -0,0 +1,87 @@ +#============================================================# +# +--------------------------------------------------------+ # +# | Kenshins Hide and Seek | # +# | Leaderboard file | # +# | by KenshinEto | # +# +--------------------------------------------------------+ # +#============================================================# +# This config file allows you to change what is displayed on the scoreboard\leaderboard +# while in the lobby, or in the game. Below are a list of predefined placeholders. +# +# LOBBY BOARD PLACEHOLDERS +# +# {COUNTDOWN} - Displays the time left in the lobby countdown. If there are not enough +# people in the lobby, or the lobby countdown its disabled, it just +# displays waiting for players. The text displayed can be changed below. +# {COUNT} - The amount of player currently in the lobby. +# {SEEKER%} - The chance that a player will be selected to be a seeker. +# {HIDER%} - The chance that a player will be selected to be a hider. +# +# GAME BOARD PLACEHOLDERS +# +# {TIME} - The amount of time left in the game in MmSs. +# {TEAM} - The team you are on. Hider, Seeker, or Spectator. +# {BORDER} - The current status of the world boarder, if enabled. +# If the world border is disabled, this line is removed +# automatically. Displays the time left until the border +# moves in MmSs, or "Decreasing" if it's decreasing. +# What is displayed exactly can be changed below. +# {TAUNT} - The current status of the taunt system, if enabled. +# If taunts are disabled, any line with {TAUNT} will be +# automatically removed. Shows the time left till next +# taunt in MmSs, if the taunt is active, and if the taunt +# has expired (one player left). What is displayed exactly +# can be changed below. +# {GLOW} - The current status of the glow powerup, if enabled. +# This line is automatically removed if the glow poewrup +# is disabled. Tells all players if a Glow powerup is active, +# only Hiders will be able to see its effects though. +# {#SEEKER} - Number of current seekers. +# {#HIDER} - Number of current hiders. +# +# YOU CANNOT USE TWO PLACEHOLDERS ON THE SAME LINE. ONLY THE FIRST ONE WILL +# BE CHANGED, AND THE SECOND ONE WILL SAY A PLACEHOLDER MARKER! + +lobby: + title: "&eHIDE AND SEEK" + content: [ + "{COUNTDOWN}", + "", + "Players: {COUNT}", + "", + "&cSEEKER % &f{SEEKER%}", + "&6HIDER % &f{HIDER%}" + ] + +game: + title: "&eHIDE AND SEEK" + content: [ + "Team: {TEAM}", + "", + "Time Left: &a{TIME}", + "", + "Taunt: &e{TAUNT}", + "Glow: {GLOW}", + "WorldBorder: &b{BORDER}", + "", + "&cSEEKERS: &f{#SEEKER}", + "&6HIDERS: &f{#HIDER}" + ] + +countdown: + waiting: "Waiting for players..." + adminStart: "Waiting for gamemaster..." + counting: "Starting in: $a{AMOUNT}s" + +taunt: + counting: "{AMOUNT}m{AMOUNT}s" + active: "Active" + expired: "Expired" + +glow: + active: "&aActive" + inactive: "&cInactive" + +border: + counting: "{AMOUNT}m{AMOUNT}s" + decreasing: "Decreasing" \ No newline at end of file From 3794537cf4435296253118bc4af84df57ae28836 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 13 Apr 2022 12:02:36 -0400 Subject: [PATCH 6/7] 1.4.0 rc2 --- pom.xml | 30 +++++++++---------- .../configuration/Localization.java | 2 +- .../hideAndSeek/database/Database.java | 20 +++++++++---- .../hideAndSeek/database/PlayerInfoTable.java | 11 +++++-- .../hideAndSeek/game/EventListener.java | 8 +++-- 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 2ca8916..1d77b2c 100644 --- a/pom.xml +++ b/pom.xml @@ -26,31 +26,31 @@ com.cryptomorin.xseries - net.tylermurphy.hideAndSeek.util.xseries + net.tylermurphy.xseries - - com.github.cryptomorin:XSeries - org.xerial:sqlite-jdbc - + + org.spigotmc:spigot-api + com.comphenix.protocol:ProtocolLib + org.jetbrains:annotations + net.bytebuddy:byte-buddy + *:* META-INF/*.MF - com/cryptomorin/xseries/XBiome* - com/cryptomorin/xseries/NMSExtras* - com/cryptomorin/xseries/NoteBlockMusic* - com/cryptomorin/xseries/SkullCacheListener* - com/cryptomorin/xseries/XBlock* - com/cryptomorin/xseries/XEntity* - com/cryptomorin/xseries/particles/* - com/cryptomorin/xseries/messages/ActionBar* + sqlite-jdbc.properties + + + META-INF/services/java.sql.Driver + + @@ -89,9 +89,7 @@ org.xerial sqlite-jdbc - 3.36.0.3 - jar - provided + 3.7.2 org.jetbrains diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java index 07402d1..b93329f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java @@ -36,7 +36,7 @@ public class Localization { public static void loadLocalization() { - ConfigManager manager = new ConfigManager("localization.yml", "lang"+File.separator+"localization_"+Config.locale +".yml"); + ConfigManager manager = new ConfigManager("localization.yml", "lang/localization_"+Config.locale +".yml"); int PLUGIN_VERSION = manager.getDefaultInt("version"); int VERSION = manager.getInt("version"); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java index 9a0837b..8001368 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/Database.java @@ -21,6 +21,8 @@ package net.tylermurphy.hideAndSeek.database; import com.google.common.io.ByteStreams; import net.tylermurphy.hideAndSeek.Main; +import org.sqlite.SQLiteConfig; +import sun.font.ScriptRun; import java.io.ByteArrayInputStream; import java.io.File; @@ -30,6 +32,8 @@ import java.nio.ByteBuffer; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; + +import java.sql.Statement; import java.util.UUID; public class Database { @@ -37,14 +41,15 @@ public class Database { private static final File databaseFile = new File(Main.data, "database.db"); public static PlayerInfoTable playerInfo; + private static SQLiteConfig config; protected static Connection connect() { Connection conn = null; try { String url = "jdbc:sqlite:"+databaseFile; - conn = DriverManager.getConnection(url); + conn = DriverManager.getConnection(url, config.toProperties()); } catch (SQLException e) { - System.out.println(e.getMessage()); + Main.plugin.getLogger().severe(e.getMessage()); } return conn; } @@ -71,10 +76,15 @@ public class Database { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { - Main.plugin.getLogger().severe("Unable to load SQLite driver!"); - System.exit(-1); - return; + Main.plugin.getLogger().severe(e.getMessage()); + throw new RuntimeException(e.getMessage()); } + + config = new SQLiteConfig(); + config.setSynchronous(SQLiteConfig.SynchronousMode.NORMAL); + config.setTempStore(SQLiteConfig.TempStore.MEMORY); + playerInfo = new PlayerInfoTable(); } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java index e859687..7b9b476 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/database/PlayerInfoTable.java @@ -20,8 +20,10 @@ package net.tylermurphy.hideAndSeek.database; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.util.WinType; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.sql.*; @@ -42,7 +44,7 @@ public class PlayerInfoTable { + ");"; try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){ - statement.execute(sql); + statement.executeUpdate(sql); } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); } @@ -59,6 +61,8 @@ public class PlayerInfoTable { statement.setBytes(1, bytes); ResultSet rs = statement.executeQuery(); if(rs.next()){ + rs.close(); + connection.close(); return new PlayerInfo( uuid, rs.getInt("wins"), @@ -67,6 +71,7 @@ public class PlayerInfoTable { rs.getInt("games_played") ); } + rs.close(); } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); } catch (IOException e) { @@ -84,7 +89,7 @@ public class PlayerInfoTable { List infoList = new ArrayList<>(); while(rs.next()){ PlayerInfo info = new PlayerInfo( - Database.convertBinaryStream(rs.getBinaryStream("uuid")), + Database.convertBinaryStream(new ByteArrayInputStream(rs.getBytes("uuid"))), rs.getInt("wins"), rs.getInt("seeker_wins"), rs.getInt("hider_wins"), @@ -92,6 +97,8 @@ public class PlayerInfoTable { ); infoList.add(info); } + rs.close(); + connection.close(); return infoList; } catch (SQLException e){ Main.plugin.getLogger().severe("SQL Error: " + e.getMessage()); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 698d650..aab55d4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -271,9 +271,13 @@ public class EventListener implements Listener { } } } + String[] temp = array[0].split(":"); for(String handle : blockedCommands){ - System.out.println(handle); - if(array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && Game.status != Status.STANDBY){ + if( + array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && + temp[temp.length-1].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) && + Game.status != Status.STANDBY + ) { player.sendMessage(errorPrefix + message("BLOCKED_COMMAND")); event.setCancelled(true); break; From 19488e62bf01ff1d9abe9aa149141d58aed801cf Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 13 Apr 2022 13:47:59 -0400 Subject: [PATCH 7/7] 1.4.0 rc3 --- .../net/tylermurphy/hideAndSeek/Main.java | 8 +- .../hideAndSeek/command/Start.java | 8 +- .../tylermurphy/hideAndSeek/game/Board.java | 87 +++++++++++-------- .../hideAndSeek/game/EventListener.java | 15 ---- .../tylermurphy/hideAndSeek/game/Game.java | 21 +++-- src/main/resources/config.yml | 3 +- 6 files changed, 77 insertions(+), 65 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java index e486cda..cdba285 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java @@ -46,7 +46,7 @@ public class Main extends JavaPlugin implements Listener { public static Main plugin; public static File root, data; - private BukkitTask onTickTask; + private int onTickTask; public void onEnable() { plugin = this; @@ -69,13 +69,13 @@ public class Main extends JavaPlugin implements Listener { } catch (Exception e) { e.printStackTrace(); } - },0,1); + },0,1).getTaskId(); } public void onDisable() { - if(onTickTask != null) - onTickTask.cancel(); + Main.plugin.getServer().getScheduler().cancelTask(onTickTask); UUIDFetcher.cleanup(); + Board.cleanup(); } public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index b82e3b5..8605764 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -24,6 +24,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import net.tylermurphy.hideAndSeek.game.Board; import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.util.Status; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -64,7 +65,12 @@ public class Start implements ICommand { } else { seekerName = args[0]; } - Player seeker = Board.getPlayer(seekerName); + Player temp = Bukkit.getPlayer(seekerName); + if(temp == null) { + sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); + return; + } + Player seeker = Board.getPlayer(temp.getUniqueId()); if(seeker == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index fd75040..e91e3da 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -34,32 +34,28 @@ import org.bukkit.scoreboard.*; public class Board { - private static final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); - private static final Map playerList = new HashMap<>(); - private static final Map customBoards = new HashMap<>(); + private static final List Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>(); + private static final Map playerList = new HashMap<>(); + private static final Map customBoards = new HashMap<>(); public static boolean isPlayer(Player player) { - return playerList.containsKey(player.getName()); - } - - public static boolean isPlayer(String name){ - return playerList.containsKey(name); + return playerList.containsKey(player.getUniqueId()); } public static boolean isPlayer(CommandSender sender) { - return playerList.containsKey(sender.getName()); + return playerList.containsKey(Bukkit.getPlayer(sender.getName()).getUniqueId()); } public static boolean isHider(Player player) { - return Hider.contains(player.getName()); + return Hider.contains(player.getUniqueId()); } public static boolean isSeeker(Player player) { - return Seeker.contains(player.getName()); + return Seeker.contains(player.getUniqueId()); } public static boolean isSpectator(Player player) { - return Spectator.contains(player.getName()); + return Spectator.contains(player.getUniqueId()); } public static int sizeHider() { @@ -74,6 +70,13 @@ public class Board { return playerList.values().size(); } + public static void check(){ + for(UUID uuid : playerList.keySet()){ + if(Bukkit.getPlayer(uuid) == null) + playerList.remove(uuid); + } + } + public static List getHiders(){ return Hider.stream().map(playerList::get).collect(Collectors.toList()); } @@ -94,42 +97,42 @@ public class Board { return new ArrayList<>(playerList.values()); } - public static Player getPlayer(String name) { - return playerList.get(name); + public static Player getPlayer(UUID uuid) { + return playerList.get(uuid); } public static void addHider(Player player) { - Hider.add(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); + Hider.add(player.getUniqueId()); + Seeker.remove(player.getUniqueId()); + Spectator.remove(player.getUniqueId()); + playerList.put(player.getUniqueId(), player); } public static void addSeeker(Player player) { - Hider.remove(player.getName()); - Seeker.add(player.getName()); - Spectator.remove(player.getName()); - playerList.put(player.getName(), player); + Hider.remove(player.getUniqueId()); + Seeker.add(player.getUniqueId()); + Spectator.remove(player.getUniqueId()); + playerList.put(player.getUniqueId(), player); } public static void addSpectator(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.add(player.getName()); - playerList.put(player.getName(), player); + Hider.remove(player.getUniqueId()); + Seeker.remove(player.getUniqueId()); + Spectator.add(player.getUniqueId()); + playerList.put(player.getUniqueId(), player); } public static void remove(Player player) { - Hider.remove(player.getName()); - Seeker.remove(player.getName()); - Spectator.remove(player.getName()); - playerList.remove(player.getName()); + Hider.remove(player.getUniqueId()); + Seeker.remove(player.getUniqueId()); + Spectator.remove(player.getUniqueId()); + playerList.remove(player.getUniqueId()); } public static boolean onSameTeam(Player player1, Player player2) { - if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true; - else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true; - else return Spectator.contains(player1.getName()) && Spectator.contains(player2.getName()); + if(Hider.contains(player1.getUniqueId()) && Hider.contains(player2.getUniqueId())) return true; + else if(Seeker.contains(player1.getUniqueId()) && Seeker.contains(player2.getUniqueId())) return true; + else return Spectator.contains(player1.getUniqueId()) && Spectator.contains(player2.getUniqueId()); } public static void reload() { @@ -143,7 +146,7 @@ public class Board { } private static void createLobbyBoard(Player player, boolean recreate) { - CustomBoard board = customBoards.get(player.getName()); + CustomBoard board = customBoards.get(player.getUniqueId()); if(recreate) { board = new CustomBoard(player, "&l&eHIDE AND SEEK"); board.updateTeams(); @@ -172,7 +175,7 @@ public class Board { i++; } board.display(); - customBoards.put(player.getName(), board); + customBoards.put(player.getUniqueId(), board); } public static void createGameBoard(Player player){ @@ -180,7 +183,7 @@ public class Board { } private static void createGameBoard(Player player, boolean recreate){ - CustomBoard board = customBoards.get(player.getName()); + CustomBoard board = customBoards.get(player.getUniqueId()); if(recreate) { board = new CustomBoard(player, GAME_TITLE); board.updateTeams(); @@ -235,14 +238,14 @@ public class Board { i++; } board.display(); - customBoards.put(player.getName(), board); + customBoards.put(player.getUniqueId(), board); } public static void removeBoard(Player player) { ScoreboardManager manager = Bukkit.getScoreboardManager(); assert manager != null; player.setScoreboard(manager.getMainScoreboard()); - customBoards.remove(player.getName()); + customBoards.remove(player.getUniqueId()); } public static void reloadLobbyBoards() { @@ -281,6 +284,14 @@ public class Board { else return ChatColor.WHITE + "UNKNOWN"; } + public static void cleanup(){ + playerList.clear(); + Hider.clear(); + Seeker.clear(); + Spectator.clear(); + customBoards.clear(); + } + } class CustomBoard { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index aab55d4..ffe452b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -40,7 +40,6 @@ import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.player.*; -import net.tylermurphy.hideAndSeek.util.Packet; import org.bukkit.potion.PotionEffect; import org.bukkit.projectiles.ProjectileSource; @@ -257,20 +256,6 @@ public class EventListener implements Listener { Player player = event.getPlayer(); String message = event.getMessage(); String[] array = message.split(" "); - if(array[0].equalsIgnoreCase("/kill")){ - if(Board.isPlayer(player)){ - Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby"); - event.setCancelled(true); - } else if(array.length > 1){ - for(int i=1; i