Skip to content

Commit

Permalink
Fix the block changer skill
Browse files Browse the repository at this point in the history
  • Loading branch information
iceBear67 committed Oct 22, 2024
1 parent bd472de commit 29f0d29
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
19 changes: 14 additions & 5 deletions src/main/java/dev/tylerm/khs/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -185,29 +188,35 @@ private List<HiderSkill> 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);
windCharge.setAmount(4);
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)
Expand All @@ -221,7 +230,7 @@ private List<HiderSkill> loadSkills() {
"&e\"望眼欲穿\"",
"&f看到所有在场猎人的位置 &8x2"
);
list.add(new HiderSkill(display,List.of(seekerVisualizer)));
list.add(new HiderSkill(display, List.of(seekerVisualizer)));
}
return list;
}
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/dev/tylerm/khs/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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) {
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/dev/tylerm/khs/game/listener/InteractHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/tylerm/khs/item/CustomItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 29f0d29

Please sign in to comment.