This commit is contained in:
YuTian 2024-08-10 20:40:24 +08:00
parent cdf96c920b
commit 2d08c6264e
17 changed files with 538 additions and 26 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target/ /target/
/.idea/ /.idea/
/out/ /out/
/EnderDragonWars.iml

View File

@ -1,19 +1,189 @@
package com.yaohun.enderdragonWars.effectevent; package com.yaohun.enderdragonwars.effectevent;
import com.yaohun.enderdragonWars.effect.GiftEffect; import com.yaohun.enderdragonwars.Main;
import com.yaohun.enderdragonWars.game.Game; 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 { 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<FallingBlock> fallingBlocks = new ArrayList<>();
protected boolean stop = false;
public BomBomEffect(String audience) { public BomBomEffect(String audience) {
super(audience); super(audience);
} }
@Override @Override
public void apply(Game game) { 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<FallingBlock> 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);
} }
} }

View File

@ -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.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -8,12 +8,13 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.Map;
public class GameManage { public class GameManager {
private HashMap<String, GiftData> giftDataMap = new HashMap<>(); private Map<String, GiftData> giftDataMap = new HashMap<>();
public GameManage(){
public GameManager() {
loadGiftData(); loadGiftData();
} }
@ -31,7 +32,7 @@ public class GameManage {
} }
} }
public HashMap<String, GiftData> getGiftDataMap() { public Map<String, GiftData> getGiftDataMap() {
return giftDataMap; return giftDataMap;
} }

View File

@ -1,9 +1,9 @@
package com.yaohun.enderdragonWars.manage; package com.yaohun.enderdragonwars.manager;
import com.yaohun.enderdragonWars.effectevent.BomBomEffect; import com.yaohun.enderdragonwars.effect.GiftEffect;
import com.yaohun.enderdragonWars.effectevent.ClearInvEffect; import com.yaohun.enderdragonwars.effect.GiftQueue;
import com.yaohun.enderdragonWars.effect.GiftEffect; import com.yaohun.enderdragonwars.effectevent.BomBomEffect;
import com.yaohun.enderdragonWars.effect.GiftQueue; import com.yaohun.enderdragonwars.effectevent.ClearInvEffect;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap; import java.util.HashMap;

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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<GiftEffect> 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<GiftEffect> getEffectQueue() {
return effectQueue;
}
public BukkitTask getTask() {
return task;
}
}

View File

@ -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) {
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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;
}
}

View File

View File

@ -1,5 +1,6 @@
name: EnderDragonWars name: EnderDragonWars
main: main: com.yaohun.enderdragonwars.Main
version: 1.0 version: 1.0
api-version: 1.20
commands: commands:
game: game: