From 1005d4a8d8eef7aae6598bd4a96eea49f902ea80 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 4 May 2022 16:30:55 -0400 Subject: [PATCH] custom model data, custom glow item, custom seeker ping --- .../hideAndSeek/configuration/Config.java | 34 +++++++++++-- .../configuration/ConfigManager.java | 9 ++++ .../hideAndSeek/game/EventListener.java | 49 ++++++++----------- .../tylermurphy/hideAndSeek/game/Game.java | 25 +++------- src/main/resources/config.yml | 18 +++++-- 5 files changed, 83 insertions(+), 52 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java index 589d3a2..39bc55f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java @@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek.configuration; import com.cryptomorin.xseries.XItemStack; import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XSound; import net.tylermurphy.hideAndSeek.util.Version; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -100,6 +101,11 @@ public class Config { lobbyItemLeavePosition, lobbyItemStartPosition; + public static float + seekerPingLeadingVolume, + seekerPingVolume, + seekerPingPitch; + public static List blockedCommands, blockedInteracts; @@ -124,7 +130,12 @@ public class Config { public static ItemStack lobbyLeaveItem, - lobbyStartItem; + lobbyStartItem, + glowPowerupItem; + + public static XSound + ringingSound, + heartbeatSound; public static void loadConfig() { @@ -196,6 +207,16 @@ public class Config { glowLength = Math.max(1, config.getInt("glow.time")); glowStackable = config.getBoolean("glow.stackable"); glowEnabled = config.getBoolean("glow.enabled") && Version.atLeast("1.9"); + if(glowEnabled) { + ConfigurationSection item = new YamlConfiguration().createSection("temp"); + item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("glow.name"))); + item.set("material", config.getString("glow.material")); + List lore = config.getStringList("glow.lore"); + if (lore != null && !lore.isEmpty()) item.set("lore", lore); + ItemStack temp = null; + try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){} + glowPowerupItem = temp; + } //Lobby minPlayers = Math.max(2, config.getInt("minPlayers")); @@ -210,6 +231,13 @@ public class Config { seekerPingLevel1 = config.getInt("seekerPing.distances.level1"); seekerPingLevel2 = config.getInt("seekerPing.distances.level2"); seekerPingLevel3 = config.getInt("seekerPing.distances.level3"); + seekerPingLeadingVolume = config.getFloat("seekerPing.sounds.leadingVolume"); + seekerPingVolume = config.getFloat("seekerPing.sounds.volume"); + seekerPingPitch = config.getFloat("seekerPing.sounds.pitch"); + Optional heartbeatOptional = XSound.matchXSound(config.getString("seekerPing.sounds.heartbeatNoise")); + heartbeatSound = heartbeatOptional.orElse(XSound.BLOCK_NOTE_BLOCK_BASEDRUM); + Optional ringingOptional = XSound.matchXSound(config.getString("seekerPing.sounds.ringingNoise")); + ringingSound = heartbeatOptional.orElse(XSound.BLOCK_NOTE_BLOCK_PLING); //Other nametagsVisible = config.getBoolean("nametagsVisible"); @@ -259,7 +287,7 @@ public class Config { item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.leave.name"))); item.set("material", config.getString("lobbyItems.leave.material")); if(Version.atLeast("1.14")){ - if(config.contains("lobbyItems.leave.model-data")){ + if(config.contains("lobbyItems.leave.model-data") && config.getInt("lobbyItems.leave.model-data") != 0){ config.set("model-data", config.getInt("lobbyItems.leave.model-data")); } } @@ -282,7 +310,7 @@ public class Config { lobbyItemStartAdmin = config.getBoolean("lobbyItems.start.adminOnly"); lobbyItemStartPosition = config.getInt("lobbyItems.start.position"); if(Version.atLeast("1.14")){ - if(config.contains("lobbyItems.start.model-data")){ + if(config.contains("lobbyItems.start.model-data") && config.getInt("lobbyItems.start.model-data") != 0){ config.set("model-data", config.getInt("lobbyItems.start.model-data")); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index 53a30c2..3546fa8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -130,6 +130,15 @@ public class ConfigManager { return defaultConfig.getInt(path); } + public float getFloat(String path){ + float value = (float) config.getDouble(path); + if(value == 0){ + return (float) defaultConfig.getDouble(path); + } else { + return value; + } + } + public String getString(String path){ String value = config.getString(path); if(value == null){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 5995dbc..e464fba 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -32,7 +32,6 @@ import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -42,7 +41,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.*; -import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.projectiles.ProjectileSource; @@ -239,24 +237,6 @@ public class EventListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST) - public void onProjectile(ProjectileLaunchEvent event) { - if(Game.status != Status.PLAYING) return; - if(event.getEntity() instanceof Snowball) { - if(!glowEnabled) return; - Snowball snowball = (Snowball) event.getEntity(); - if(snowball.getShooter() instanceof Player) { - Player player = (Player) snowball.getShooter(); - if(Board.isHider(player)) { - Game.glow.onProjectile(); - snowball.remove(); - assert XMaterial.SNOWBALL.parseMaterial() != null; - player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial()); - } - } - } - } - @EventHandler(priority = EventPriority.HIGHEST) public void onFoodLevelChange(FoodLevelChangeEvent event) { if(event.getEntity() instanceof Player) { @@ -297,18 +277,19 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerInteract(PlayerInteractEvent event) { if(!Board.isPlayer(event.getPlayer())) return; - if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null && blockedInteracts.contains(event.getClickedBlock().getType().name())){ event.setCancelled(true); return; } - - if(Game.status != Status.STANDBY) return; - - ItemStack temp = event.getItem(); if(temp == null) return; + if(Game.status == Status.STANDBY) + onPlayerInteractLobby(temp, event); + if(Game.status == Status.PLAYING) + onPlayerInteractGame(temp, event); + } + private void onPlayerInteractLobby(ItemStack temp, PlayerInteractEvent event){ if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyLeaveItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyLeaveItem.getType()) { event.setCancelled(true); Game.leave(event.getPlayer()); @@ -330,7 +311,20 @@ public class EventListener implements Listener { } Game.start(); } + } + private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event){ + if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(glowPowerupItem.getItemMeta().getDisplayName()) && temp.getType() == glowPowerupItem.getType()) { + if(!glowEnabled) return; + Player player = event.getPlayer(); + if(Board.isHider(player)) { + Game.glow.onProjectile(); + player.getInventory().remove(glowPowerupItem); + assert XMaterial.SNOWBALL.parseMaterial() != null; + player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial()); + event.setCancelled(true); + } + } } @EventHandler(priority = EventPriority.HIGHEST) @@ -344,9 +338,8 @@ public class EventListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST) - public void onItemDrop(PlayerDropItemEvent event) - { - if(Board.isPlayer(event.getPlayer()) && Game.status == Status.STANDBY){ + public void onItemDrop(PlayerDropItemEvent event) { + if(Board.isPlayer(event.getPlayer())){ event.setCancelled(true); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index c01682b..7488163 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -273,18 +273,7 @@ public class Game { for(PotionEffect effect : Items.HIDER_EFFECTS) player.addPotionEffect(effect); if(glowEnabled) { - assert XMaterial.SNOWBALL.parseMaterial() != null; - ItemStack snowball = new ItemStack(XMaterial.SNOWBALL.parseMaterial(), 1); - ItemMeta snowballMeta = snowball.getItemMeta(); - assert snowballMeta != null; - snowballMeta.setDisplayName("Glow Powerup"); - List snowballLore = new ArrayList<>(); - snowballLore.add("Throw to make all seekers glow"); - snowballLore.add("Last 30s, all hiders can see it"); - snowballLore.add("Time stacks on multi use"); - snowballMeta.setLore(snowballLore); - snowball.setItemMeta(snowballMeta); - player.getInventory().addItem(snowball); + player.getInventory().addItem(glowPowerupItem); } } } @@ -391,18 +380,18 @@ public class Game { } if(seekerPing) switch(tick%10) { case 0: - if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .5f, 1f); - if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); + if(distance < seekerPingLevel1) heartbeatSound.play(hider, seekerPingLeadingVolume, seekerPingPitch); + if(distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch); break; case 3: - if(distance < seekerPingLevel1) XSound.BLOCK_NOTE_BLOCK_BASEDRUM.play(hider, .3f, 1f); - if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); + if(distance < seekerPingLevel1) heartbeatSound.play(hider, seekerPingVolume, seekerPingPitch); + if(distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch); break; case 6: - if(distance < seekerPingLevel3) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); + if(distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch); break; case 9: - if(distance < seekerPingLevel2) XSound.BLOCK_NOTE_BLOCK_PLING.play(hider, .3f, 1f); + if(distance < seekerPingLevel2) ringingSound.play(hider, seekerPingVolume, seekerPingPitch); break; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9a82052..8e52343 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -99,6 +99,9 @@ glow: time: 30 stackable: true enabled: true + name: "Glow Powerup" + lore: [ "Throw to make all seekers glow", "Last 30s, all hiders can see it", "Time stacks on multi use" ] + material: SNOWBALL # The message prefixes displayed before messages. The message contents themselves # can be changed in localization.yml. @@ -124,21 +127,24 @@ lobby: # Below are the two items given to you when you join a lobby. A item to click to leave the lobby, and another # to start the game. Each of these items can be toggled separately, but only these items are currently supported. -# You can customize the material, name, lore, and position of the item. And finally, the start item is marked as -# adminOnly be default since the /hs start command is also admin by default. If you set adminOnly to false, only -# the item will become non admin only, not the command. +# You can customize the material, name, lore, and position of the item. You can also change the model data if your +# server is running 1.14 or above. Any earlier version, the model-data tag will be ignored; Model-data 0 is also ignored. +# Finally, the start item is marked as adminOnly be default since the /hs start command is also admin by default. +# If you set adminOnly to false, only the item will become non admin only, not the command. lobbyItems: leave: material: BED name: "&cLeave Lobby" lore: ["Go back to server hub"] position: 8 + model-data: 0 enabled: true start: material: CLOCK name: "&bStart Game" lore: [] position: 0 + model-data: 0 enabled: true adminOnly: true @@ -150,6 +156,12 @@ seekerPing: level1: 30 level2: 20 level3: 10 + sounds: + leadingVolume: 0.5 + volume: 0.3 + pitch: 1 + heartbeatNoise: BLOCK_NOTE_BLOCK_BASEDRUM + ringingNoise: BLOCK_NOTE_BLOCK_PLING enabled: true # Changes the default plugin language. Currently, Supported localizations are: