From 29f0d295563ce45ae623c1f590b4e5e4e1772475 Mon Sep 17 00:00:00 2001 From: iceBear67 Date: Tue, 22 Oct 2024 13:54:22 +0800 Subject: [PATCH] Fix the block changer skill --- src/main/java/dev/tylerm/khs/Main.java | 19 +++++++++++---- src/main/java/dev/tylerm/khs/game/Game.java | 14 ++++------- .../khs/game/listener/InteractHandler.java | 24 ++++++++++++------- .../java/dev/tylerm/khs/item/CustomItems.java | 1 + 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/main/java/dev/tylerm/khs/Main.java b/src/main/java/dev/tylerm/khs/Main.java index 3a149de..7df9f6b 100644 --- a/src/main/java/dev/tylerm/khs/Main.java +++ b/src/main/java/dev/tylerm/khs/Main.java @@ -166,6 +166,9 @@ public void onEnable() { Bukkit.getPluginManager().registerEvents(new SkillSelectionGUI.InventoryHandler(), Main.getInstance()); Bukkit.getPluginManager().registerEvents(new MenuFunctionListener(), this); long end = System.currentTimeMillis(); + if (!Bukkit.getServer().getAllowFlight()) { + getLogger().severe("Allow flight is set to false. Players may be kicked if they stand on solidifed hiders."); + } getLogger().info("Finished loading plugin (" + (end - start) + "ms)"); loaded = true; } @@ -185,7 +188,7 @@ private List loadSkills() { "&a动力小子", "&c肾上腺素 &fx2 &8[速度 III 5s]" ); - list.add(new HiderSkill(display,List.of(spdyPotion))); + list.add(new HiderSkill(display, List.of(spdyPotion))); } { var windCharge = new ItemStack(Material.WIND_CHARGE); @@ -193,21 +196,27 @@ private List loadSkills() { var display = ItemStacks.of( Material.WIND_CHARGE, "&b弹弓", - "风弹 x4" + "&f风弹 x4" ); - list.add(new HiderSkill(display,List.of(windCharge))); + list.add(new HiderSkill(display, List.of(windCharge))); } { var blockChanger = ItemStacks.builder(Material.BLAZE_ROD) .customModelId(CustomItems.BLOCK_CHANGER) .displayName("&d失控魔杖") + .lore("&f随机变成某种方块") .build(); var display = ItemStacks.of( Material.BLAZE_ROD, "&d我是谁?", "&f随机变成某种方块" ); - list.add(new HiderSkill(display,List.of(blockChanger))); + var blindnessWand = ItemStacks.builder(Material.BREEZE_ROD) + .customModelId(CustomItems.BLINDNESS_WAND) + .displayName("&1失明魔杖") + .lore("&f使周围的猎人失明 6s.") + .build(); + list.add(new HiderSkill(display, List.of(blockChanger, blindnessWand))); } { var seekerVisualizer = ItemStacks.builder(Material.SNOWBALL) @@ -221,7 +230,7 @@ private List loadSkills() { "&e\"望眼欲穿\"", "&f看到所有在场猎人的位置 &8x2" ); - list.add(new HiderSkill(display,List.of(seekerVisualizer))); + list.add(new HiderSkill(display, List.of(seekerVisualizer))); } return list; } diff --git a/src/main/java/dev/tylerm/khs/game/Game.java b/src/main/java/dev/tylerm/khs/game/Game.java index 99cbf2a..414e417 100644 --- a/src/main/java/dev/tylerm/khs/game/Game.java +++ b/src/main/java/dev/tylerm/khs/game/Game.java @@ -310,16 +310,10 @@ private void whileStarting() { private void whilePlaying() { for (Player hider : board.getHiders()) { - int distance = 100, temp = 100; + double distance = 100; for (Player seeker : board.getSeekers()) { - try { - temp = (int) hider.getLocation().distance(seeker.getLocation()); - } catch (Exception e) { - //Players in different worlds, NOT OK!!! - } - if (distance > temp) { - distance = temp; - } + if (hider.getLocation().getWorld() != seeker.getLocation().getWorld()) continue; + distance = Math.min(distance, hider.getLocation().distanceSquared(seeker.getLocation())); } if (seekerPing) switch (gameTick % 10) { case 0: @@ -339,7 +333,7 @@ private void whilePlaying() { break; } } - if (gameTick % 10 == 0 && gameTimer < whenToHighlight ) { + if (gameTick % 10 == 0 && gameTimer < whenToHighlight) { for (Player seeker : board.getSeekers()) { for (Entity nearbyEntity : seeker.getNearbyEntities(8, 2, 8)) { if (nearbyEntity instanceof Player player) { 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 5c5f5bd..12171c3 100644 --- a/src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java +++ b/src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java @@ -5,7 +5,6 @@ import dev.tylerm.khs.Main; import dev.tylerm.khs.game.Board; import dev.tylerm.khs.game.util.Status; -import dev.tylerm.khs.gui.BlockPickerGUI; import dev.tylerm.khs.item.CustomItems; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -25,7 +24,9 @@ import java.util.ArrayList; import java.util.List; +import java.util.Random; import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; import static dev.tylerm.khs.configuration.Config.*; import static dev.tylerm.khs.configuration.Localization.message; @@ -79,11 +80,16 @@ private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event) { switch (CustomItems.getId(temp)) { case CustomItems.BLOCK_CHANGER -> { player.getInventory().remove(temp); - new BlockPickerGUI( - event.getPlayer(), - Main.getInstance().getGame().getCurrentMap(), - () -> { - }); + var game = Main.getInstance().getGame(); + var selectableBlocks = game.getCurrentMap().getBlockHunt(); + var rand = selectableBlocks.get(ThreadLocalRandom.current().nextInt(selectableBlocks.size())); + Main.getInstance().getDisguiser().disguise(player ,rand, game.getCurrentMap()); + } + case CustomItems.BLINDNESS_WAND -> { + player.getInventory().remove(temp); + for (Player seeker : Main.getInstance().getBoard().getSeekers()) { + seeker.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 6 * 20, 2)); + } } case CustomItems.SEEKER_VISUALIZER -> { var glow = Main.getInstance().getGame().getGlow(); @@ -101,14 +107,14 @@ private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event) { if (p != null) glow.setGlow(user, p, false); } - }, 3 * 20); + }, 5 * 20); } case CustomItems.SPEED_POTION -> { temp.setAmount(temp.getAmount() - 1); player.addPotionEffect(new PotionEffect( PotionEffectType.SPEED, - 20 * 5, - 3 + 20 * 6, + 4 )); } } diff --git a/src/main/java/dev/tylerm/khs/item/CustomItems.java b/src/main/java/dev/tylerm/khs/item/CustomItems.java index a9b352b..72b1825 100644 --- a/src/main/java/dev/tylerm/khs/item/CustomItems.java +++ b/src/main/java/dev/tylerm/khs/item/CustomItems.java @@ -11,6 +11,7 @@ public class CustomItems { public static final int SPEED_POTION = 10; public static final int BLOCK_CHANGER = 11; public static final int SEEKER_VISUALIZER = 12; + public static final int BLINDNESS_WAND = 13; public static int getId(ItemStack stack){ if(stack.getItemMeta() == null || !stack.getItemMeta().hasCustomModelData()) return -1;