diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index bbb3479..92782a2 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -48,23 +48,4 @@ jobs: # gradle-version: '8.9' # # - name: Build with Gradle 8.9 - # run: gradle build - - dependency-submission: - - runs-on: ubuntu-latest - permissions: - contents: write - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. - # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md - - name: Generate and submit dependency graph - uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + # run: gradle build \ No newline at end of file diff --git a/build.gradle b/build.gradle index 18f488c..cae7dca 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'dev.tylerm' -version = '1.8.1a' +version = '1.8.3a' description = 'Hide and Seek Plugin' java.sourceCompatibility = JavaVersion.VERSION_21 diff --git a/src/main/java/dev/tylerm/khs/Main.java b/src/main/java/dev/tylerm/khs/Main.java index 6ce8dda..bf7f3b5 100644 --- a/src/main/java/dev/tylerm/khs/Main.java +++ b/src/main/java/dev/tylerm/khs/Main.java @@ -213,7 +213,7 @@ private List loadSkills() { var display = ItemStacks.of( Material.WIND_CHARGE, "&b弹弓", - "&f风弹 x4", + "&f风弹 x2", "&a砸中别人会很痛。" ); list.add(new HiderSkill(display, List.of(windCharge))); diff --git a/src/main/java/dev/tylerm/khs/configuration/Config.java b/src/main/java/dev/tylerm/khs/configuration/Config.java index 09eb867..21436fd 100644 --- a/src/main/java/dev/tylerm/khs/configuration/Config.java +++ b/src/main/java/dev/tylerm/khs/configuration/Config.java @@ -70,6 +70,7 @@ public class Config { regenHealth; public static int + maxPlayers, minPlayers, gameLength, extendPerKill, @@ -161,6 +162,7 @@ public static void loadConfig() { //Lobby startingSeekerCount = Math.max(1, config.getInt("startingSeekerCount")); waitTillNoneLeft = config.getBoolean("waitTillNoneLeft"); + maxPlayers = config.getInt("maxPlayers"); minPlayers = Math.max(1 + startingSeekerCount + (waitTillNoneLeft ? 0 : 1), config.getInt("minPlayers")); countdown = Math.max(10, config.getInt("lobby.countdown")); changeCountdown = Math.max(minPlayers, config.getInt("lobby.changeCountdown")); diff --git a/src/main/java/dev/tylerm/khs/event/DamagedByWindChargeEvent.java b/src/main/java/dev/tylerm/khs/event/DamagedByWindChargeEvent.java new file mode 100644 index 0000000..7b11add --- /dev/null +++ b/src/main/java/dev/tylerm/khs/event/DamagedByWindChargeEvent.java @@ -0,0 +1,28 @@ +package dev.tylerm.khs.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class DamagedByWindChargeEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final Player player; + + public DamagedByWindChargeEvent(Player player) { + this.player = player; + } + + public Player getPlayer() { + return player; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/dev/tylerm/khs/event/GameStartedEvent.java b/src/main/java/dev/tylerm/khs/event/GameStartedEvent.java new file mode 100644 index 0000000..26febc5 --- /dev/null +++ b/src/main/java/dev/tylerm/khs/event/GameStartedEvent.java @@ -0,0 +1,19 @@ +package dev.tylerm.khs.event; + +import dev.tylerm.khs.game.util.WinType; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class GameStartedEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/dev/tylerm/khs/event/HitByBeeBirdEvent.java b/src/main/java/dev/tylerm/khs/event/HitByBeeBirdEvent.java new file mode 100644 index 0000000..d100b65 --- /dev/null +++ b/src/main/java/dev/tylerm/khs/event/HitByBeeBirdEvent.java @@ -0,0 +1,28 @@ +package dev.tylerm.khs.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class HitByBeeBirdEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final Player player; + + public HitByBeeBirdEvent(Player player) { + this.player = player; + } + + public Player getPlayer() { + return player; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/dev/tylerm/khs/game/Game.java b/src/main/java/dev/tylerm/khs/game/Game.java index 0405877..9865875 100644 --- a/src/main/java/dev/tylerm/khs/game/Game.java +++ b/src/main/java/dev/tylerm/khs/game/Game.java @@ -24,6 +24,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import dev.tylerm.khs.event.GameEndEvent; +import dev.tylerm.khs.event.GameStartedEvent; import dev.tylerm.khs.game.events.Glow; import dev.tylerm.khs.game.events.Taunt; import dev.tylerm.khs.game.listener.RespawnHandler; @@ -288,6 +289,7 @@ private void whileStarting() { currentMap.getGameSpawn().teleport(player); } }); + Bukkit.getPluginManager().callEvent(new GameStartedEvent()); } else if (startingTimer == 1) { message = message("START_COUNTDOWN_LAST").addAmount(startingTimer).toString(); } else { diff --git a/src/main/java/dev/tylerm/khs/game/listener/DamageHandler.java b/src/main/java/dev/tylerm/khs/game/listener/DamageHandler.java index a3f3fd5..f6d1c25 100644 --- a/src/main/java/dev/tylerm/khs/game/listener/DamageHandler.java +++ b/src/main/java/dev/tylerm/khs/game/listener/DamageHandler.java @@ -2,6 +2,8 @@ import com.cryptomorin.xseries.XSound; import dev.tylerm.khs.Main; +import dev.tylerm.khs.event.DamagedByWindChargeEvent; +import dev.tylerm.khs.event.HitByBeeBirdEvent; import dev.tylerm.khs.event.PlayerKillEvent; import dev.tylerm.khs.game.Board; import dev.tylerm.khs.game.Game; @@ -35,24 +37,30 @@ public void onProjectileHit(ProjectileHitEvent event) { var hitEntity = event.getHitEntity(); var hitBlock = event.getHitBlock(); - if(hitBlock != null && directEntity.hasMetadata(CustomItems.OWL_BOW_METADATA_KEY)){ - new SpecialArrowTaunt(hitBlock.getLocation().add(0,1,0), 32).runTaskTimer(Main.getInstance(), 0L, 5L); + if (hitBlock != null && directEntity.hasMetadata(CustomItems.OWL_BOW_METADATA_KEY)) { + new SpecialArrowTaunt(hitBlock.getLocation().add(0, 1, 0), 32).runTaskTimer(Main.getInstance(), 0L, 5L); directEntity.remove(); return; } - if(hitEntity instanceof Player player){ - if(Main.getInstance().getBoard().isHider(player)){ + if (hitEntity instanceof Player player) { + if (Main.getInstance().getBoard().isHider(player)) { //todo test Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { player.setArrowsInBody(0); }, 10L); } if (directEntity instanceof WindCharge) { - if (player != directEntity.getShooter() && player.getHealth() > 6.5) { - player.setHealth(player.getHealth() - 6.5); - //todo: test 风弹伤害 - return; - } + directEntity.getNearbyEntities(0.7, 0.7, 0.7).forEach(entity -> { + if (!(entity instanceof Player) || Main.getInstance().getBoard().isSpectator((Player) entity)) { + return; + } + var p = (Player) entity; + if (p != directEntity.getShooter() && p.getHealth() > 6.5) { + p.setHealth(p.getHealth() - 6.5); + Bukkit.getPluginManager().callEvent(new DamagedByWindChargeEvent(p)); + //todo: test 风弹伤害 + } + }); } } } @@ -87,6 +95,7 @@ else if (((EntityDamageByEntityEvent) event).getDamager() instanceof Projectile) new SpecialArrowTaunt(player.getLocation(), 32) .runTaskTimer(Main.getInstance(), 0L, 5L); event.setDamage(0); + Bukkit.getPluginManager().callEvent(new HitByBeeBirdEvent(player)); return; } } diff --git a/src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java b/src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java index f2b92d2..e75b0a6 100644 --- a/src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java +++ b/src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java @@ -84,7 +84,6 @@ private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event) { switch (CustomItems.getId(temp)) { case CustomItems.BLOCK_CHANGER -> { var game = Main.getInstance().getGame(); - var selectableBlocks = game.getCurrentMap().getBlockHunt(); // find a block var hiders = Main.getInstance().getBoard().getHiders(); if (hiders.size() == 1) { @@ -106,7 +105,7 @@ private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event) { text = TextComponent.fromLegacy(ChatColor.LIGHT_PURPLE + "你现在变成了 "); text.addExtra(new TranslatableComponent(targetDisguise.getMaterial().getBlockTranslationKey())); text.addExtra("!"); - player.spigot().sendMessage(text); //todo test 换装 + player.spigot().sendMessage(text); player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2 * 20, 1)); selected.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2 * 20, 1)); @@ -145,7 +144,6 @@ private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event) { )); player.sendMessage(ChatColor.RED+"你被加速了,快跑!"); } - } } diff --git a/src/main/java/dev/tylerm/khs/game/listener/JoinLeaveHandler.java b/src/main/java/dev/tylerm/khs/game/listener/JoinLeaveHandler.java index 4bd8129..cd2ce97 100644 --- a/src/main/java/dev/tylerm/khs/game/listener/JoinLeaveHandler.java +++ b/src/main/java/dev/tylerm/khs/game/listener/JoinLeaveHandler.java @@ -35,6 +35,9 @@ public void onPlayerJoin(PlayerJoinEvent event) { return; } Main.getInstance().getGame().join(event.getPlayer()); + if(Main.getInstance().getBoard().getPlayers().size() >= lobbyMax){ + Main.getInstance().getGame().start(); + } } else if (teleportToExit) { if ( event.getPlayer().getWorld().getName().equals(Main.getInstance().getGame().getCurrentMap().getLobbyName()) || diff --git a/src/main/java/dev/tylerm/khs/task/AnnounceBlockTypeTask.java b/src/main/java/dev/tylerm/khs/task/AnnounceBlockTypeTask.java index cd70a7d..16692f9 100644 --- a/src/main/java/dev/tylerm/khs/task/AnnounceBlockTypeTask.java +++ b/src/main/java/dev/tylerm/khs/task/AnnounceBlockTypeTask.java @@ -7,21 +7,27 @@ import net.md_5.bungee.api.chat.TranslatableComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import java.util.concurrent.ThreadLocalRandom; + public class AnnounceBlockTypeTask extends BukkitRunnable { private static BaseComponent EMPTY = TextComponent.fromLegacy(""); + @Override public void run() { - if(Main.getInstance().getGame().getStatus() != Status.PLAYING) return; + if (Main.getInstance().getGame().getStatus() != Status.PLAYING) return; BaseComponent v; - if(Main.getInstance().getBoard().getHiders().isEmpty()){ + if (Main.getInstance().getBoard().getHiders().isEmpty()) { v = EMPTY; - }else{ - var first = Main.getInstance().getDisguiser().getDisguise(Main.getInstance().getBoard().getHiders().getFirst()); - v = new TranslatableComponent(first.getMaterial().getBlockTranslationKey()); + } else { + var hiders = Main.getInstance().getBoard().getHiders(); + Player randomHider = hiders.get(ThreadLocalRandom.current().nextInt(hiders.size())); + var disguise = Main.getInstance().getDisguiser().getDisguise(randomHider); + v = new TranslatableComponent(disguise.getMaterial().getBlockTranslationKey()); } - var text = TextComponent.fromLegacy(ChatColor.GREEN+" TIP: "+ChatColor.WHITE+"场上有一个"); + var text = TextComponent.fromLegacy(ChatColor.GREEN + " TIP: " + ChatColor.WHITE + "场上有一个 "); text.addExtra(v); text.addExtra(" 方块!"); Bukkit.spigot().broadcast(text);