From 832e93a2ef47b5f7fb3058c3bfb1bad289035640 Mon Sep 17 00:00:00 2001 From: yaohunya <31456652@qq.com> Date: Sun, 11 Aug 2024 13:59:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=881.0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../effect/types/RandomBox.java | 71 +++++++++++++++++++ .../effect/types/SummonIronGolem.java | 2 + .../effect/types/SummonMobs.java | 32 +++++++++ .../effect/types/WuHuJump.java | 46 ++++++++++++ .../com/yaohun/enderdragonwars/game/Game.java | 3 + .../manager/GiftEffectManager.java | 2 + 6 files changed, 156 insertions(+) create mode 100644 src/main/java/com/yaohun/enderdragonwars/effect/types/RandomBox.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/effect/types/SummonMobs.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/effect/types/WuHuJump.java diff --git a/src/main/java/com/yaohun/enderdragonwars/effect/types/RandomBox.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/RandomBox.java new file mode 100644 index 0000000..5ee26f4 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/effect/types/RandomBox.java @@ -0,0 +1,71 @@ +package com.yaohun.enderdragonwars.effect.types; + +import com.sk89q.worldedit.world.entity.EntityType; +import com.yaohun.enderdragonwars.Main; +import com.yaohun.enderdragonwars.effect.GiftEffect; +import com.yaohun.enderdragonwars.game.Game; +import com.yaohun.enderdragonwars.manager.GiftEffectManager; +import net.kyori.adventure.sound.Sound; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +public class RandomBox extends GiftEffect { + + public RandomBox(String audience) { + super(audience); + } + + @Override + public void apply(Game game) { + Player player = game.getPlayer(); + List stringList = new ArrayList<>(); + stringList.add("清理背包"); + stringList.add("火山喷发"); + stringList.add("幸运方块"); + stringList.add("黑洞"); + stringList.add("五雷轰顶"); + stringList.add("装备清空"); + stringList.add("岩浆泡澡"); + stringList.add("钢铁保安"); + stringList.add("6倍血量"); + stringList.add("原地复活"); + stringList.add("魔豆天梯"); + stringList.add("世界毁灭"); + stringList.add("变大"); + stringList.add("变小"); + stringList.add("安全庇护所"); + stringList.add("螺旋升天"); + stringList.add("怪物军团"); + Collections.shuffle(stringList); + Random random = new Random(); + String eventName = stringList.get(random.nextInt(stringList.size())); + BukkitTask task = new BukkitRunnable() { + private int i = 0; + @Override + public void run() { + if (i >= 12) { + player.sendTitle("§6随机盲盒","§9整蛊效果: §e"+eventName); + player.playSound(player.getLocation(),Sound.BLOCK_COMPARATOR_CLICK,1,1); + GiftEffectManager.addGiftEffect(getAudience(),eventName); + Bukkit.broadcastMessage("§c[消息]§a随机盲盒抽中了 §e"+eventName); + cancel(); + return; + } + player.sendTitle("§6随机盲盒","§9整蛊效果: §e"+stringList.get(random.nextInt(stringList.size()))); + player.playSound(player.getLocation(),Sound.BLOCK_COMPARATOR_CLICK,1,1); + i++; + } + }.runTaskTimer(Main.plugin, 0L, 5L); + Main.game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonIronGolem.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonIronGolem.java index 60f10b5..b18ae21 100644 --- a/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonIronGolem.java +++ b/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonIronGolem.java @@ -15,6 +15,8 @@ public class SummonIronGolem extends GiftEffect { public void apply(Game game) { Player player = game.getPlayer(); player.getWorld().spawnEntity(player.getLocation(), EntityType.IRON_GOLEM); + player.getWorld().spawnEntity(player.getLocation(), EntityType.IRON_GOLEM); + player.getWorld().spawnEntity(player.getLocation(), EntityType.IRON_GOLEM); } } diff --git a/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonMobs.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonMobs.java new file mode 100644 index 0000000..e9aab9a --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/effect/types/SummonMobs.java @@ -0,0 +1,32 @@ +package com.yaohun.enderdragonwars.effect.types; + +import com.yaohun.enderdragonwars.effect.GiftEffect; +import com.yaohun.enderdragonwars.game.Game; +import com.yaohun.enderdragonwars.util.RandomUtil; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Zombie; +import org.bukkit.util.Vector; + +public class SummonMobs extends GiftEffect { + + public SummonMobs(String audience) { + super(audience); + } + + @Override + public void apply(Game game) { + Player player = game.getPlayer(); + for (int i = 0; i < 5;i++){ + Zombie zombie = (Zombie) player.getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE); + zombie.setVelocity(new Vector(RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1))); + } + for (int i = 0; i < 5;i++){ + Creeper creeper = (Creeper) player.getWorld().spawnEntity(player.getLocation(), EntityType.CREEPER); + creeper.setVelocity(new Vector(RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1))); + } + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/effect/types/WuHuJump.java b/src/main/java/com/yaohun/enderdragonwars/effect/types/WuHuJump.java new file mode 100644 index 0000000..431321c --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/effect/types/WuHuJump.java @@ -0,0 +1,46 @@ +package com.yaohun.enderdragonwars.effect.types; + +import com.sk89q.worldedit.world.entity.EntityType; +import com.yaohun.enderdragonwars.Main; +import com.yaohun.enderdragonwars.effect.GiftEffect; +import com.yaohun.enderdragonwars.game.Game; +import com.yaohun.enderdragonwars.util.RandomUtil; +import net.kyori.adventure.sound.Sound; +import org.bukkit.Location; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.entity.Zombie; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.bukkit.util.Vector; + +public class WuHuJump extends GiftEffect { + + public WuHuJump(String audience) { + super(audience); + } + + @Override + public void apply(Game game) { + Player player = game.getPlayer(); + player.setVelocity(player.getLocation().getDirection().multiply(0.5).setY(1.0)); + player.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 10); + player.playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1.0F, 1.0F); + BukkitTask task = new BukkitRunnable() { + private int i= 0; + @Override + public void run() { + if(i >= 4){cancel();} + Location location = player.getLocation(); + TNTPrimed tntPrimed = (TNTPrimed) location.getWorld().spawnEntity(location.clone().add(0,-0.5,0), EntityType.PRIMED_TNT); + tntPrimed.setFuseTicks(5); + tntPrimed.setYield(0.0F); + location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f); + i++; + } + }.runTaskTimer(Main.plugin, 2L,1L); + game.addTasks(task); + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/game/Game.java b/src/main/java/com/yaohun/enderdragonwars/game/Game.java index 3fa5ce0..330a77a 100644 --- a/src/main/java/com/yaohun/enderdragonwars/game/Game.java +++ b/src/main/java/com/yaohun/enderdragonwars/game/Game.java @@ -119,6 +119,9 @@ public class Game { return startd; } + public void addTasks(BukkitTask task){ + this.tasks.add(task); + } public long getLiveTime() { return liveTime; } diff --git a/src/main/java/com/yaohun/enderdragonwars/manager/GiftEffectManager.java b/src/main/java/com/yaohun/enderdragonwars/manager/GiftEffectManager.java index 60b2c14..25cff5b 100644 --- a/src/main/java/com/yaohun/enderdragonwars/manager/GiftEffectManager.java +++ b/src/main/java/com/yaohun/enderdragonwars/manager/GiftEffectManager.java @@ -56,6 +56,8 @@ public class GiftEffectManager { registerGiftEffect("变小", PlayerSmallEffect::new); registerGiftEffect("安全庇护所", SpawnBuildEffect::new); registerGiftEffect("螺旋升天", ToHeavenEffect::new); + registerGiftEffect("怪物军团", SummonMobs::new); + registerGiftEffect("芜湖起飞", WuHuJump::new); } private static void registerGiftEffect(String id, Function giftEffectGetter) {