From 2d08c6264e2c0faf9ce470d72ce5cbf04360e7f4 Mon Sep 17 00:00:00 2001 From: YuTian <2953516620@qq.com> Date: Sat, 10 Aug 2024 20:40:24 +0800 Subject: [PATCH] 0.5 --- .gitignore | 1 + .../effectevent/BomBomEffect.java | 182 +++++++++++++++++- .../GameManager.java} | 29 +-- .../GiftEffectManager.java | 10 +- .../enderdragonWars/util/EntityUtil.java | 13 ++ .../java/com/yaohun/enderdragonwars/Main.java | 45 +++++ .../yaohun/enderdragonwars/data/GiftData.java | 41 ++++ .../enderdragonwars/effect/GiftEffect.java | 23 +++ .../enderdragonwars/effect/GiftQueue.java | 55 ++++++ .../effectevent/ClearInvEffect.java | 17 ++ .../com/yaohun/enderdragonwars/game/Game.java | 38 ++++ .../liveevent/GiftEventHandler.java | 13 ++ .../yaohun/enderdragonwars/util/GameUtil.java | 28 +++ .../yaohun/enderdragonwars/util/GiftUtil.java | 35 ++++ .../enderdragonwars/util/RandomUtil.java | 31 +++ src/main/resources/config.yml | 0 src/main/resources/plugin.yml | 3 +- 17 files changed, 538 insertions(+), 26 deletions(-) rename src/main/java/com/yaohun/enderdragonWars/{manage/GameManage.java => manager/GameManager.java} (54%) rename src/main/java/com/yaohun/enderdragonWars/{manage => manager}/GiftEffectManager.java (84%) create mode 100644 src/main/java/com/yaohun/enderdragonWars/util/EntityUtil.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/Main.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/data/GiftData.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/effect/GiftEffect.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/effect/GiftQueue.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/effectevent/ClearInvEffect.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/game/Game.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/liveevent/GiftEventHandler.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/util/GameUtil.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/util/GiftUtil.java create mode 100644 src/main/java/com/yaohun/enderdragonwars/util/RandomUtil.java create mode 100644 src/main/resources/config.yml diff --git a/.gitignore b/.gitignore index a86a754..0b0322a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target/ /.idea/ /out/ +/EnderDragonWars.iml diff --git a/src/main/java/com/yaohun/enderdragonWars/effectevent/BomBomEffect.java b/src/main/java/com/yaohun/enderdragonWars/effectevent/BomBomEffect.java index 1d86797..b5132e6 100644 --- a/src/main/java/com/yaohun/enderdragonWars/effectevent/BomBomEffect.java +++ b/src/main/java/com/yaohun/enderdragonWars/effectevent/BomBomEffect.java @@ -1,19 +1,189 @@ -package com.yaohun.enderdragonWars.effectevent; +package com.yaohun.enderdragonwars.effectevent; -import com.yaohun.enderdragonWars.effect.GiftEffect; -import com.yaohun.enderdragonWars.game.Game; +import com.yaohun.enderdragonwars.Main; +import com.yaohun.enderdragonwars.effect.GiftEffect; +import com.yaohun.enderdragonwars.game.Game; +import com.yaohun.enderdragonwars.util.EntityUtil; +import net.kyori.adventure.text.Component; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ColorableArmorMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; public class BomBomEffect extends GiftEffect { + private static final ItemStack ITEM_1; + private static final ItemStack ITEM_2; + private static final ItemStack ITEM_3; + private static final ItemStack ITEM_4; + + private static final ItemStack ITEM_5; + private static final ItemStack ITEM_6; + private static final ItemStack ITEM_7; + + private List fallingBlocks = new ArrayList<>(); + + protected boolean stop = false; + public BomBomEffect(String audience) { super(audience); } @Override public void apply(Game game) { - /* - * 参考群内视频 火山喷发 - * */ + World world = game.getWorld(); + Player player = game.getPlayer(); + ArmorStand armorStand = (ArmorStand) world.spawnEntity(player.getLocation(), EntityType.ARMOR_STAND, CreatureSpawnEvent.SpawnReason.CUSTOM, (entity)->{ + ArmorStand armorStand1 = (ArmorStand) entity; + armorStand1.setArms(true); + armorStand1.setBasePlate(false); + armorStand1.customName(Component.text("§4§l毁天灭地")); + armorStand1.setCustomNameVisible(true); + armorStand1.setDisabledSlots(EquipmentSlot.values()); + armorStand1.setInvulnerable(true); + armorStand1.setGravity(false); + armorStand1.getEquipment().setItemInMainHand(ITEM_1); + armorStand1.getEquipment().setItemInOffHand(ITEM_1); + armorStand1.getEquipment().setItem(EquipmentSlot.HEAD, ITEM_1); + armorStand1.getEquipment().setItem(EquipmentSlot.CHEST, ITEM_2); + armorStand1.getEquipment().setItem(EquipmentSlot.LEGS, ITEM_3); + armorStand1.getEquipment().setItem(EquipmentSlot.FEET, ITEM_4); + }); + new BukkitRunnable() { + private int count = 0; + @Override + public void run() { + if (count >= 10) { + armorStand.remove(); + for (int i =0; i < 3; i++) { + armorStand.getWorld().createExplosion(armorStand.getLocation(), 5f, true, true); + } + stop = true; + cancel(); + return; + } + Random random = new Random(); + for (int i = 0; i < 30; i++) { + FallingBlock fallingBlock = (FallingBlock) world.spawnEntity(armorStand.getLocation(), EntityType.FALLING_BLOCK, CreatureSpawnEvent.SpawnReason.CUSTOM, (fallingBlockEntity)->{ + FallingBlock fallingBlock1 = (FallingBlock) fallingBlockEntity; + fallingBlock1.setBlockData(Bukkit.createBlockData(Material.MAGMA_BLOCK)); + fallingBlock1.setDropItem(false); + fallingBlock1.setCancelDrop(true); + fallingBlock1.setFireTicks(200); + }); + fallingBlocks.add(fallingBlock); + EntityUtil.shoot(fallingBlock, (Math.random() * 2.5D - 1.5D) * 0.1f, 0.4f + Math.random() * 0.15f, (Math.random() * 2.5D - 1.5D) * 0.1f, 3f + random.nextFloat() * 1.5f, 0f); + player.getWorld().playSound(fallingBlock.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1f, 1f); + } + count++; + } + }.runTaskTimer(Main.plugin, 0L, 15L); + new BukkitRunnable() { + private int count = 0; + @Override + public void run() { + if (stop) { + cancel(); + return; + } + boolean flag = count % 2 == 0; + armorStand.customName(Component.text(flag? "§4§l毁天灭地" : "§c§l毁天灭地")); + armorStand.getEquipment().setItem(EquipmentSlot.CHEST, flag ? ITEM_2 : ITEM_5); + armorStand.getEquipment().setItem(EquipmentSlot.LEGS, flag ? ITEM_3 : ITEM_6); + armorStand.getEquipment().setItem(EquipmentSlot.FEET, flag ? ITEM_4 : ITEM_7); + count++; + } + }.runTaskTimer(Main.plugin, 0L, 5L); + new BukkitRunnable() { + private int count = 0; + @Override + public void run() { + if (stop) { + cancel(); + return; + } + float f = count * 25F; + armorStand.setRotation(f, 0); + Location location1 = armorStand.getLocation().clone().add(0, 0.35, 0); + armorStand.getWorld().spawnParticle(Particle.LAVA, location1, 5, 0.2, 0.6, 0.2, 0.05); + armorStand.getWorld().spawnParticle(Particle.FLAME, location1, 5, 0.2, 1, 0.2, 0.01); + count++; + } + }.runTaskTimer(Main.plugin, 0L, 2L); + new BukkitRunnable() { + private int count = 0; + @Override + public void run() { + if (fallingBlocks.isEmpty()) { + cancel(); + return; + } + Iterator iterator = fallingBlocks.iterator(); + while (iterator.hasNext()) { + FallingBlock fallingBlock = iterator.next(); + Location location = fallingBlock.getLocation().add(0, -2, 0); + Block block = location.getBlock(); + if (block.getType() != Material.AIR) { + location.getWorld().createExplosion(location, 5f, true, true); + location.add(0, 1, 0).getBlock().setType(Material.LAVA); + fallingBlock.remove(); + iterator.remove(); + } + } + count++; + } + }.runTaskTimer(Main.plugin, 0L, 2L); + } + + static { + ITEM_1 = new ItemStack(Material.TNT); + ITEM_2 = new ItemStack(Material.LEATHER_CHESTPLATE); + ITEM_3 = new ItemStack(Material.LEATHER_LEGGINGS); + ITEM_4 = new ItemStack(Material.LEATHER_BOOTS); + ITEM_5 = new ItemStack(Material.LEATHER_CHESTPLATE); + ITEM_6 = new ItemStack(Material.LEATHER_LEGGINGS); + ITEM_7 = new ItemStack(Material.LEATHER_BOOTS); + Color color1 = Color.fromRGB(214, 41, 0); + Color color2 = Color.fromRGB(255, 133, 102); + ItemMeta itemMeta2 = ITEM_2.getItemMeta(); + ColorableArmorMeta colorableArmorMeta2 = (ColorableArmorMeta) itemMeta2; + colorableArmorMeta2.setColor(color1); + ITEM_2.setItemMeta(colorableArmorMeta2); + ItemMeta itemMeta3 = ITEM_3.getItemMeta(); + ColorableArmorMeta colorableArmorMeta3 = (ColorableArmorMeta) itemMeta3; + colorableArmorMeta3.setColor(color1); + ITEM_3.setItemMeta(colorableArmorMeta3); + ItemMeta itemMeta4 = ITEM_4.getItemMeta(); + ColorableArmorMeta colorableArmorMeta4 = (ColorableArmorMeta) itemMeta4; + colorableArmorMeta4.setColor(color1); + ITEM_4.setItemMeta(colorableArmorMeta4); + ItemMeta itemMeta5 = ITEM_5.getItemMeta(); + ColorableArmorMeta colorableArmorMeta5 = (ColorableArmorMeta) itemMeta5; + colorableArmorMeta5.setColor(color2); + ITEM_5.setItemMeta(colorableArmorMeta5); + ItemMeta itemMeta6 = ITEM_6.getItemMeta(); + ColorableArmorMeta colorableArmorMeta6 = (ColorableArmorMeta) itemMeta6; + colorableArmorMeta6.setColor(color2); + ITEM_6.setItemMeta(colorableArmorMeta6); + ItemMeta itemMeta7 = ITEM_7.getItemMeta(); + ColorableArmorMeta colorableArmorMeta7 = (ColorableArmorMeta) itemMeta7; + colorableArmorMeta7.setColor(color2); + ITEM_7.setItemMeta(colorableArmorMeta7); } + } diff --git a/src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java b/src/main/java/com/yaohun/enderdragonWars/manager/GameManager.java similarity index 54% rename from src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java rename to src/main/java/com/yaohun/enderdragonWars/manager/GameManager.java index ba3d53c..f3c3d75 100644 --- a/src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java +++ b/src/main/java/com/yaohun/enderdragonWars/manager/GameManager.java @@ -1,6 +1,6 @@ -package com.yaohun.enderdragonWars.manage; +package com.yaohun.enderdragonwars.manager; -import com.yaohun.enderdragonWars.data.GiftData; +import com.yaohun.enderdragonwars.data.GiftData; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -8,35 +8,36 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.util.HashMap; -import java.util.LinkedHashMap; +import java.util.Map; -public class GameManage { +public class GameManager { - private HashMap giftDataMap = new HashMap<>(); - public GameManage(){ + private Map giftDataMap = new HashMap<>(); + + public GameManager() { loadGiftData(); } - public void loadGiftData(){ - File file = new File("./plugins/游戏设置","礼物设置.yml"); + public void loadGiftData() { + File file = new File("./plugins/游戏设置", "礼物设置.yml"); FileConfiguration yml = YamlConfiguration.loadConfiguration(file); Bukkit.getConsoleSender().sendMessage("[日志 - 末影龙挑战] 事件注册:"); ConfigurationSection section = yml.getConfigurationSection("礼物设置"); - if(section == null){ + if (section == null) { System.out.println("[错误 - 游戏] 礼物设置错误,请检查文件."); return; } - for (String giftName : section.getKeys(false)){ - giftDataMap.put(giftName,new GiftData(giftName,yml)); + for (String giftName : section.getKeys(false)) { + giftDataMap.put(giftName, new GiftData(giftName, yml)); } } - public HashMap getGiftDataMap() { + public Map getGiftDataMap() { return giftDataMap; } - public GiftData getGiftData(String giftName){ - if(getGiftDataMap().get(giftName) == null){ + public GiftData getGiftData(String giftName) { + if (getGiftDataMap().get(giftName) == null) { return null; } return getGiftDataMap().get(giftName); diff --git a/src/main/java/com/yaohun/enderdragonWars/manage/GiftEffectManager.java b/src/main/java/com/yaohun/enderdragonWars/manager/GiftEffectManager.java similarity index 84% rename from src/main/java/com/yaohun/enderdragonWars/manage/GiftEffectManager.java rename to src/main/java/com/yaohun/enderdragonWars/manager/GiftEffectManager.java index e67b560..5f9a8f7 100644 --- a/src/main/java/com/yaohun/enderdragonWars/manage/GiftEffectManager.java +++ b/src/main/java/com/yaohun/enderdragonWars/manager/GiftEffectManager.java @@ -1,9 +1,9 @@ -package com.yaohun.enderdragonWars.manage; +package com.yaohun.enderdragonwars.manager; -import com.yaohun.enderdragonWars.effectevent.BomBomEffect; -import com.yaohun.enderdragonWars.effectevent.ClearInvEffect; -import com.yaohun.enderdragonWars.effect.GiftEffect; -import com.yaohun.enderdragonWars.effect.GiftQueue; +import com.yaohun.enderdragonwars.effect.GiftEffect; +import com.yaohun.enderdragonwars.effect.GiftQueue; +import com.yaohun.enderdragonwars.effectevent.BomBomEffect; +import com.yaohun.enderdragonwars.effectevent.ClearInvEffect; import org.bukkit.scheduler.BukkitTask; import java.util.HashMap; diff --git a/src/main/java/com/yaohun/enderdragonWars/util/EntityUtil.java b/src/main/java/com/yaohun/enderdragonWars/util/EntityUtil.java new file mode 100644 index 0000000..a14cf27 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonWars/util/EntityUtil.java @@ -0,0 +1,13 @@ +package com.yaohun.enderdragonwars.util; + +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; + +public class EntityUtil { + + public static void shoot(Entity entity, double p_37266_, double p_37267_, double p_37268_, float p_37269_, float p_37270_) { + Vector vec3 = new Vector(p_37266_, p_37267_, p_37268_).normalize().add(new Vector(RandomUtil.triangle(0.0D, 0.0172275D * (double)p_37270_), RandomUtil.triangle(0.0D, 0.0172275D * (double)p_37270_), RandomUtil.triangle(0.0D, 0.0172275D * (double)p_37270_))).multiply(p_37269_); + entity.setVelocity(vec3); + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/Main.java b/src/main/java/com/yaohun/enderdragonwars/Main.java new file mode 100644 index 0000000..2557ef9 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/Main.java @@ -0,0 +1,45 @@ +package com.yaohun.enderdragonwars; + +import com.yaohun.enderdragonwars.effectevent.BomBomEffect; +import com.yaohun.enderdragonwars.game.Game; +import com.yaohun.enderdragonwars.manager.GameManager; +import com.yaohun.enderdragonwars.manager.GiftEffectManager; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +public class Main extends JavaPlugin { + + public static Main plugin; + public static GameManager gameManager; + public static Game game; + + @Override + public void onEnable() { + plugin = this; + GiftEffectManager.registerAll(); + gameManager = new GameManager(); + game = new Game(); + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (args.length == 1) { + String subCommand = args[0]; + Player player = (Player) sender; + game.startGame(player); + if (subCommand.equalsIgnoreCase("1")) { + new BomBomEffect(player.getName()).apply(game); + } + } + return true; + } + + @Override + public void onDisable() { + GiftEffectManager.stopQueue(); + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/data/GiftData.java b/src/main/java/com/yaohun/enderdragonwars/data/GiftData.java new file mode 100644 index 0000000..8b81ce1 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/data/GiftData.java @@ -0,0 +1,41 @@ +package com.yaohun.enderdragonwars.data; + +import com.yaohun.enderdragonwars.util.GameUtil; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; + +public class GiftData { + private String giftName; // 礼物名 + private String event; // 效果名 + private int minutes; // 加播或减播 + private String sounds; // 自定义音效 + + public GiftData(String giftName, FileConfiguration yml) { + this.giftName = giftName; + String str = "礼物设置." + giftName + "."; + if (yml.getString(str + "声音") != null) { + this.sounds = yml.getString(str + "声音"); + } + this.event = yml.getString(str + "效果"); + this.minutes = yml.getInt(str + "加播"); + if (this.minutes >= 1) { + Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName + " 加播: +" + minutes + "分钟"); + } else { + Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName + " 减播: -" + minutes + "分钟"); + } + } + + public String getGiftName() { + return giftName; + } + + public String getEvent() { + return event; + } + + public void outPlaySoundEvent() { + if (!sounds.equalsIgnoreCase("NULL")) { + GameUtil.sendAllSound(sounds); + } + } +} diff --git a/src/main/java/com/yaohun/enderdragonwars/effect/GiftEffect.java b/src/main/java/com/yaohun/enderdragonwars/effect/GiftEffect.java new file mode 100644 index 0000000..d6960dc --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/effect/GiftEffect.java @@ -0,0 +1,23 @@ +package com.yaohun.enderdragonwars.effect; + +import com.yaohun.enderdragonwars.game.Game; + +public abstract class GiftEffect { + + private String audience; + + public GiftEffect(String audience) { + this.audience = audience; + } + + public String getAudience() { + return audience; + } + + public abstract void apply(Game game); + + public int getQueueTime() { + return 20; + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/effect/GiftQueue.java b/src/main/java/com/yaohun/enderdragonwars/effect/GiftQueue.java new file mode 100644 index 0000000..917b30b --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/effect/GiftQueue.java @@ -0,0 +1,55 @@ +package com.yaohun.enderdragonwars.effect; + +import com.yaohun.enderdragonwars.Main; +import com.yaohun.enderdragonwars.game.Game; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitTask; + +import java.util.LinkedList; +import java.util.Queue; + +public class GiftQueue { + + private Queue effectQueue = new LinkedList<>(); + + private BukkitTask task; + + public GiftQueue(int waitTime) { + task = Bukkit.getScheduler().runTaskTimer(Main.plugin, new Runnable() { + private int timer = 0; + private boolean running = false; + + @Override + public void run() { + timer++; + if (!running) { + timer = waitTime; + running = true; + } + if (timer >= waitTime) { + timer = 0; + if (effectQueue.isEmpty()) { + running = false; + return; + } + Game game = Main.game; + GiftEffect effect = effectQueue.poll(); + effect.apply(game); + } + } + }, 0L, 1L); + } + + public void addEffect(GiftEffect effect) { + effectQueue.add(effect); + } + + public Queue getEffectQueue() { + return effectQueue; + } + + public BukkitTask getTask() { + return task; + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/effectevent/ClearInvEffect.java b/src/main/java/com/yaohun/enderdragonwars/effectevent/ClearInvEffect.java new file mode 100644 index 0000000..0378bd4 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/effectevent/ClearInvEffect.java @@ -0,0 +1,17 @@ +package com.yaohun.enderdragonwars.effectevent; + +import com.yaohun.enderdragonwars.effect.GiftEffect; +import com.yaohun.enderdragonwars.game.Game; + +public class ClearInvEffect extends GiftEffect { + + public ClearInvEffect(String audience) { + super(audience); + } + + @Override + public void apply(Game game) { + + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/game/Game.java b/src/main/java/com/yaohun/enderdragonwars/game/Game.java new file mode 100644 index 0000000..570cb68 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/game/Game.java @@ -0,0 +1,38 @@ +package com.yaohun.enderdragonwars.game; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +public class Game { + + private Player player; + private World world; + private boolean startd; + + private int remainTime; + + public Game() { + } + + public void startGame(Player player) { + if (startd) { + return; + } + this.player = player; + this.world = player.getWorld(); + this.startd = true; + } + + public Player getPlayer() { + return player; + } + + public World getWorld() { + return world; + } + + public int getRemainTime() { + return remainTime; + } + +} diff --git a/src/main/java/com/yaohun/enderdragonwars/liveevent/GiftEventHandler.java b/src/main/java/com/yaohun/enderdragonwars/liveevent/GiftEventHandler.java new file mode 100644 index 0000000..ebfe163 --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/liveevent/GiftEventHandler.java @@ -0,0 +1,13 @@ +package com.yaohun.enderdragonwars.liveevent; + +import com.yaohun.enderdragonwars.manager.GiftEffectManager; +import org.bukkit.entity.Player; + +public class GiftEventHandler { + + public static void handlerEffect(Player zhubo, String hideName, String eventName) { + if (eventName.equalsIgnoreCase("清空背包")) { + GiftEffectManager.addGiftEffect(hideName, eventName); + } + } +} diff --git a/src/main/java/com/yaohun/enderdragonwars/util/GameUtil.java b/src/main/java/com/yaohun/enderdragonwars/util/GameUtil.java new file mode 100644 index 0000000..698fb4e --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/util/GameUtil.java @@ -0,0 +1,28 @@ +package com.yaohun.enderdragonwars.util; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class GameUtil { + + public static String hideName(String audience) { + if (audience.length() <= 2) { + return "**"; + } + char firstChar = audience.charAt(0); + char lastChar = audience.charAt(audience.length() - 1); + StringBuilder maskedString = new StringBuilder(); + for (int i = 1; i < audience.length() - 1; i++) { + maskedString.append('*'); + } + return String.valueOf(firstChar) + maskedString + lastChar; + } + + public static void sendAllSound(String sound) { + for (Player player : Bukkit.getOnlinePlayers()) { + if (!sound.contains("_")) { + player.playSound(player.getLocation(), sound, 0.5F, 1); + } + } + } +} diff --git a/src/main/java/com/yaohun/enderdragonwars/util/GiftUtil.java b/src/main/java/com/yaohun/enderdragonwars/util/GiftUtil.java new file mode 100644 index 0000000..60e9e4e --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/util/GiftUtil.java @@ -0,0 +1,35 @@ +package com.yaohun.enderdragonwars.util; + +import com.yaohun.enderdragonwars.Main; +import com.yaohun.enderdragonwars.data.GiftData; +import com.yaohun.enderdragonwars.liveevent.GiftEventHandler; +import com.yaohun.enderdragonwars.manager.GameManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class GiftUtil { + + // 执行礼物效果 + public static void executeGiftEffect(Player zhubo, String userName, String giftName, int giftAmount) { + GameManager gameManage = Main.gameManager; + if (gameManage.getGiftData(giftName) == null) { + zhubo.sendMessage("§c[系统]§a礼物 " + giftName + " 的未设置任何礼物效果."); + return; + } + GiftData giftData = gameManage.getGiftData(giftName); + String hideName = GameUtil.hideName(userName); + String eventName = giftData.getEvent(); + if (giftAmount <= 1) { + giftData.playSoundEvent(); + GiftEventHandler.handlerEffect(zhubo, userName, eventName); + } else { + long dadey = 5L; + for (int i = 0; i < giftAmount; i++) { + Bukkit.getScheduler().runTaskLater(Main.plugin, () -> { + giftData.playSoundEvent(); + GiftEventHandler.handlerEffect(zhubo, userName, eventName); + }, (long) i * dadey); + } + } + } +} diff --git a/src/main/java/com/yaohun/enderdragonwars/util/RandomUtil.java b/src/main/java/com/yaohun/enderdragonwars/util/RandomUtil.java new file mode 100644 index 0000000..d578ebe --- /dev/null +++ b/src/main/java/com/yaohun/enderdragonwars/util/RandomUtil.java @@ -0,0 +1,31 @@ +package com.yaohun.enderdragonwars.util; + +import java.util.Random; + +public class RandomUtil { + + public static boolean random(double d) { + return d >= new Random().nextFloat(); + } + + public static double triangle(double d1, double d2) { + Random r = new Random(); + return d1 + d2 * (r.nextDouble() - r.nextDouble()); + } + + public static int getRandomInt(int min, int max) { + if (min == max) { + return max; + } + Random r = new Random(); + int i = min < max ? min : max; + int a = min < max ? max : min; + return r.nextInt(a - i + 1) + i; + } + + public static double getRandomDouble(double min, double max, int scl) { + int pow = (int) Math.pow(10, scl); + return Math.floor((Math.random() * (max - min) + min) * pow) / pow; + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index abf881b..f0c92cf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: EnderDragonWars -main: +main: com.yaohun.enderdragonwars.Main version: 1.0 +api-version: 1.20 commands: game: \ No newline at end of file