diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/game')
3 files changed, 91 insertions, 31 deletions
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 { + 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.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); + 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; } } |