测试版

This commit is contained in:
yaohunya 2024-07-31 11:20:48 +08:00
parent be7aac96fe
commit 9389a76b0a
25 changed files with 2109 additions and 147 deletions

View File

@ -0,0 +1,77 @@
package me.Demon.BlockWars.Data;
import de.tr7zw.nbtapi.NBTItem;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.GameUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
public class GameEditGui implements Listener {
public static String invTitle = "我的世界整蛊 - 游戏设置管理";
@EventHandler
public void onClick(InventoryClickEvent e){
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
ItemStack item = e.getCurrentItem();
if(e.getView().getTitle().equalsIgnoreCase(invTitle)){
e.setCancelled(true);
if(item == null || item.getType() == Material.AIR){
return;
}
}
}
public static void OpenGui(Player p){
Inventory inv = Bukkit.createInventory(null,36,invTitle);
inv.setItem(26,Edit_Comparator());
p.openInventory(inv);
}
public static ItemStack Edit_Comparator(){
ItemStack item = new ItemStack(Material.COMPARATOR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §a游戏参数设置");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add("§c回车或T键打开聊天栏点击设置");
lore.add(" ");
lore.add("§b★ §6鼠标点击 §7查看参数设置");
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
public static ItemStack Rest_Server(){
ItemStack item = new ItemStack(Material.PAPER);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e重启游戏");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add("§c重启后修改参数将生效");
lore.add(" ");
lore.add("§b★ §6鼠标点击 §7开始重启");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(55);
item.setItemMeta(meta);
return item;
}
}

View File

@ -0,0 +1,79 @@
package me.Demon.BlockWars.Data;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.GameUtil;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
public class GiftData {
private String giftName;
private String event;
private String comple_type;
private String sounds;
private int amount = 0;
private GameData game;
public GiftData(String giftName,FileConfiguration yml){
this.game = Main.gameData;
String str = "礼物设置."+giftName+".";
this.giftName = giftName;
this.comple_type = "NULL";
if(yml.getString(str+"进度") != null){
String[] stringSp = yml.getString(str+"进度").split("#");
String tpye = stringSp[0];
int a = Integer.parseInt(stringSp[1]);
this.comple_type = tpye;
this.amount = a;
}
this.sounds = "NULL";
if(yml.getString(str+"声音") != null){
this.sounds = yml.getString(str+"声音");
}
this.event = yml.getString(str + "效果");
if (comple_type.equalsIgnoreCase("NULL")) {
Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName);
}else{
if(comple_type.equalsIgnoreCase("take")){
Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName+""+amount+"");
} else if(comple_type.equalsIgnoreCase("add")){
Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName+""+amount+"");
}
}
}
public String getGiftName() {
return giftName;
}
public String getEvent() {
return event;
}
public String getComple_Show() {
if(comple_type.equalsIgnoreCase("take")){
return "§c赢-"+amount;
}else if(comple_type.equalsIgnoreCase("add")){
return "§b赢+"+amount;
}
return "";
}
public void OutCompleEvent(int amount) {
int new_amount = this.amount * amount;
if(comple_type.equalsIgnoreCase("take")){
Main.gameData.effect_takeComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §c-"+new_amount);
} else if(comple_type.equalsIgnoreCase("add")){
Main.gameData.effect_addComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §b+"+new_amount);
}
}
public void OutPlaySoundsEvent() {
if(!sounds.equalsIgnoreCase("NULL")) {
GameUtil.SendAllSounds(sounds);
}
}
}

View File

@ -0,0 +1,189 @@
package me.Demon.BlockWars.Data;
import com.yaohun.RandomBox.api.RBoxAPI;
import com.yaohun.bwaddon.api.ExtendAPI;
import de.tr7zw.nbtapi.NBTItem;
import me.Demon.BlockWars.LiveEvent.GiftEventHandler;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RepairGiftGui implements Listener {
public static String invTitle = "我的世界整蛊 - 礼物触发管理";
@EventHandler
public void onClick(InventoryClickEvent e){
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if(e.getView().getTitle().equalsIgnoreCase(invTitle)){
if(rawSlot >= 0) {
e.setCancelled(true);
zhubo.closeInventory();
ItemStack stack = e.getCurrentItem();
if (stack != null && stack.getType() != Material.AIR) {
NBTItem nbti = new NBTItem(stack);
if (nbti.hasKey("giftName")) {
String giftName = nbti.getString("giftName");
String userName = "抖音"+ RandomUtil.getRandomInt(1,100);
int amount = 1;
if (e.getClick() == ClickType.RIGHT) {
amount = 10;
} else if (e.getClick() == ClickType.SHIFT_LEFT) {
amount = 66;
}else if (e.getClick() == ClickType.SHIFT_RIGHT) {
amount = 188;
}
if(Main.configYml.getGiftData(giftName) == null){
zhubo.sendTitle("§r", "§c未设置效果",10, 30, 10);
return;
}
GiftData giftData = Main.configYml.getGiftData(giftName);
giftData.OutCompleEvent(amount);
String hide_userName = GameUtil.HideName(userName);
String eventName = giftData.getEvent();
if(GameUtil.specialGiftEffectTriggers(zhubo,eventName,hide_userName,amount)){
return;
}
String eventName_Show = eventName;
if(amount >= 2) {
String title = "§c" + eventName_Show + " x" + amount;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle,0, 30, 10);
}else{
String title = "§c" + eventName_Show;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle,0, 30, 10);
}
if (amount <= 1) {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, userName, eventName);
} else {
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, userName, eventName);
}, (long) i * 5);
}
}
}
}
}
}
}
public static void OpenGui(Player p){
Inventory inv = Bukkit.createInventory(null,27,invTitle);
HashMap<String,ItemStack> hashMap = new HashMap<>();
hashMap.put("ONE礼挑一", stackGift("ONE礼挑一", 1));
hashMap.put("Thuglife", stackGift("Thuglife", 2));
hashMap.put("爱的纸鹤", stackGift("爱的纸鹤", 3));
hashMap.put("爱你哟", stackGift("爱你哟", 4));
hashMap.put("棒棒糖", stackGift("棒棒糖", 5));
hashMap.put("比心", stackGift("比心", 6));
hashMap.put("比心兔兔", stackGift("比心兔兔", 7));
hashMap.put("称心如意", stackGift("称心如意", 8));
hashMap.put("大啤酒", stackGift("大啤酒", 9));
hashMap.put("点亮孤单", stackGift("点亮孤单", 10));
hashMap.put("抖音", stackGift("抖音", 11));
hashMap.put("抖音1号", stackGift("抖音1号", 12));
hashMap.put("多喝热水", stackGift("多喝热水", 13));
hashMap.put("繁花秘语", stackGift("繁花秘语", 14));
hashMap.put("粉丝团灯牌", stackGift("粉丝团灯牌", 15));
hashMap.put("光之祝福", stackGift("光之祝福", 16));
hashMap.put("豪华邮轮", stackGift("豪华邮轮", 17));
hashMap.put("花开烂漫", stackGift("花开烂漫", 18));
hashMap.put("花落长亭", stackGift("花落长亭", 19));
hashMap.put("环球旅行车", stackGift("环球旅行车", 20));
hashMap.put("黄桃罐头", stackGift("黄桃罐头", 21));
hashMap.put("加油鸭", stackGift("加油鸭", 22));
hashMap.put("嘉年华", stackGift("嘉年华", 23));
hashMap.put("浪漫花火", stackGift("浪漫花火", 24));
hashMap.put("礼花筒", stackGift("礼花筒", 25));
hashMap.put("龙抬头", stackGift("龙抬头", 26));
hashMap.put("玫瑰", stackGift("玫瑰", 27));
hashMap.put("你最好看", stackGift("你最好看", 28));
hashMap.put("捏捏小脸", stackGift("捏捏小脸", 29));
hashMap.put("跑车", stackGift("跑车", 30));
hashMap.put("保时捷", stackGift("保时捷", 30));
hashMap.put("怦然心动", stackGift("怦然心动", 31));
hashMap.put("亲吻", stackGift("亲吻", 32));
hashMap.put("拳拳出击", stackGift("拳拳出击", 33));
hashMap.put("热气球", stackGift("热气球", 34));
hashMap.put("人气票", stackGift("人气票", 35));
hashMap.put("日出相伴", stackGift("日出相伴", 36));
hashMap.put("闪耀星辰", stackGift("闪耀星辰", 37));
hashMap.put("私人飞机", stackGift("私人飞机", 38));
hashMap.put("送你花花", stackGift("送你花花", 39));
hashMap.put("万象烟花", stackGift("万象烟花", 40));
hashMap.put("为你闪耀", stackGift("为你闪耀", 41));
hashMap.put("为你举牌", stackGift("为你举牌", 42));
hashMap.put("鲜花", stackGift("鲜花", 43));
hashMap.put("小心心", stackGift("小心心", 44));
hashMap.put("星星点灯", stackGift("星星点灯", 45));
hashMap.put("一点心意", stackGift("一点心意", 46));
hashMap.put("一束花开", stackGift("一束花开", 47));
hashMap.put("荧光棒", stackGift("荧光棒", 48));
hashMap.put("游戏手柄", stackGift("游戏手柄", 49));
hashMap.put("掌上明珠", stackGift("掌上明珠", 50));
hashMap.put("真爱玫瑰", stackGift("真爱玫瑰", 51));
hashMap.put("真的爱你", stackGift("真的爱你", 52));
hashMap.put("直升机", stackGift("直升机", 53));
hashMap.put("纸短情长", stackGift("纸短情长", 54));
hashMap.put("蝶 · 比翼鸟", stackGift("蝶 · 比翼鸟", 56));
hashMap.put("永生花", stackGift("永生花", 57));
HashMap<String, GiftData> giftData = Main.configYml.getGiftData();
for (String giftName : giftData.keySet()){
if(hashMap.get(giftName) != null){
inv.addItem(hashMap.get(giftName));
}else{
inv.addItem(stackGift(giftName,-1));
}
}
p.openInventory(inv);
}
public static ItemStack stackGift(String name,int model_id) {
ItemStack item = new ItemStack(Material.PAPER);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d§l★ §e礼物: " + name);
List<String> lore = new ArrayList<>();
if (Main.configYml.getGiftData(name) != null) {
GiftData giftData = Main.configYml.getGiftData(name);
lore.add("§7触发效果: §a" + giftData.getEvent() + " " + giftData.getComple_Show());
} else {
lore.add("§7触发效果: §c无");
}
lore.add(" ");
lore.add("§b§l★ §6左键点击 §7召唤1次");
lore.add("§b§l★ §6右键点击 §7召唤10次");
lore.add("§b§l★ §6SHIFT+左键 §7召唤66次");
lore.add("§b§l★ §6SHIFT+右键 §7召唤188次");
meta.setLore(lore);
if (model_id >= 1){
meta.setCustomModelData(model_id);
}else{
item.setType(Material.DIAMOND);
}
item.setItemMeta(meta);
NBTItem nbti = new NBTItem(item);
nbti.setString("giftName",name);
item = nbti.getItem();
return item;
}
}

View File

@ -1,40 +0,0 @@
package me.Demon.BlockWars.Eventi;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Game.Region;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class MinerChangeEvent extends Event {
private static HandlerList handlers = new HandlerList();
private final GameData game;
private final Region region;
private final String eventType;
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public MinerChangeEvent(GameData game, Region region,String eventType) {
this.game = game;
this.region = region;
this.eventType = eventType;
}
public GameData getGame() {
return game;
}
public Region getRegion() {
return region;
}
public String getEventType() {
return eventType;
}
}

View File

@ -0,0 +1,103 @@
package me.Demon.BlockWars.Game;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.*;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
public class EffectEntity {
public static GameData game = Main.gameData;
public static void effect_Rotate_360(Player zhubo) {
if(!game.isStarted()){
return;
}
BukkitTask task = new BukkitRunnable() {
double yaw = 0;
long startTime = System.currentTimeMillis();
@Override
public void run() {
yaw += 1.5; // 每次旋转2度
if (yaw >= 360) {
yaw -= 360;
}
Vector direction = zhubo.getLocation().getDirection();
double angle = Math.toRadians(yaw);
double newX = direction.getX() * Math.cos(angle) - direction.getZ() * Math.sin(angle);
double newZ = direction.getX() * Math.sin(angle) + direction.getZ() * Math.cos(angle);
direction.setX(newX);
direction.setZ(newZ);
zhubo.teleport(zhubo.getLocation().setDirection(direction));
long currentTime = System.currentTimeMillis();
if (currentTime - startTime >= 4000) {
cancel();
}
}
}.runTaskTimer(Main.plugin, 0L, 2L);
game.addTasks(task);
zhubo.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 4, 5,false,false));
}
public static void effect_spawn_pig(Player player, String userName, int amount) {
if (!game.isStarted()) {
return;
}
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Location loc = player.getLocation();
loc.getWorld().spawnParticle(Particle.LAVA, loc, 5, 1, 1, 1, 0.085);
Vector launchVector = new Vector(RandomUtil.getRandomDouble(-0.5, 0.5, 1), RandomUtil.getRandomDouble(0, 0.5, 1), RandomUtil.getRandomDouble(-0.5, 0.5, 1));
Pig pig = (Pig) loc.getWorld().spawnEntity(loc, EntityType.PIG);
pig.setHealth(1);
pig.setCustomName("§b"+userName);
pig.setCustomNameVisible(true);
pig.setVelocity(launchVector);
player.playSound(player.getLocation(), "fangpi", 1.0F, 1.0F);
}, (long) i * 5);
}
}
public static void effect_spawn_Zombie(Player player,String userName,int amount) {
if (!game.isStarted()) {
return;
}
Region region = game.getRegion();
for (int i = 0; i < amount;i++) {
Location location = RandomUtil.getRandomLocation(player,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, region.getMax().getY()+3, region.getMax().getY()+6, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
Vector launchVector = new Vector(RandomUtil.getRandomDouble(-0.5, 0.5, 1), RandomUtil.getRandomDouble(-1, 0, 1), RandomUtil.getRandomDouble(-0.5, 0.5, 1));
location.getWorld().spawnParticle(Particle.LAVA, location, 5, 1, 1, 1, 0.085);
Zombie entity = (Zombie) location.getWorld().spawnEntity(location, EntityType.ZOMBIE);
entity.setBaby(false);
entity.setMaxHealth(2);
entity.setCustomName("§c" + userName);
entity.setCustomNameVisible(true);
entity.setVelocity(launchVector);
player.playSound(player.getLocation(), "fangpi", 1.0F, 1.0F);
}
}
public static void effect_spawn_IronGolem(Player player,String userName,int amount) {
if (!game.isStarted()) {
return;
}
Region region = game.getRegion();
for (int i = 0; i < amount;i++) {
Location location = RandomUtil.getRandomLocation(player,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, region.getMax().getY()+3, region.getMax().getY()+6, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
Vector launchVector = new Vector(RandomUtil.getRandomDouble(-0.5, 0.5, 1), RandomUtil.getRandomDouble(-1, -0.5, 1), RandomUtil.getRandomDouble(-0.5, 0.5, 1));
location.getWorld().spawnParticle(Particle.LAVA, location, 5, 1, 1, 1, 0.085);
IronGolem entity = (IronGolem) location.getWorld().spawnEntity(location, EntityType.IRON_GOLEM);
entity.setMaxHealth(10);
entity.setCustomName("§a" + userName);
entity.setCustomNameVisible(true);
entity.setVelocity(launchVector);
player.playSound(player.getLocation(), "fangpi", 1.0F, 1.0F);
}
}
}

View File

@ -0,0 +1,137 @@
package me.Demon.BlockWars.Game;
import cn.hamster3.cdapi.CDTimeAPI;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public abstract class EffectTime {
public static GameData game = Main.gameData;
public static void effect_moveBlock(Player player) {
if (!game.isStarted()) {
return;
}
UUID uuid = player.getUniqueId();
String cd_key = "move_remove_block";
if(CDTimeAPI.getCD(uuid,cd_key) >= 1){
long move_time = CDTimeAPI.getCD(uuid,cd_key) + (1000 * 15);
CDTimeAPI.setPlayerCD(uuid,cd_key,move_time);
}else{
CDTimeAPI.setPlayerCD(uuid,cd_key,1000 * 15);
}
Vector launchVector = new Vector(0, 1, 0);
player.setVelocity(launchVector);
player.playSound(player.getLocation(),"niganma",1,1);
}
public static Set<Block> getRandomUpBlocks(Region region, int amount) {
List<Block> blocks = new ArrayList<>();
for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) {
for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) {
t:
for (int y = (int) Math.floor(region.getMax().getY()); y >= region.getMin().getY(); y--) {
Block block = region.getWorld().getBlockAt(x, y, z);
if (!block.getType().equals(Material.AIR)) {
blocks.add(block);
break;
}
}
}
}
Set<Block> blocks1 = new HashSet<>();
for (int i = 0; i < amount; i++) {
int k = RandomUtil.getRandomInt(0, blocks.size() - 1);
Block block = blocks.remove(k);
blocks1.add(block);
}
return blocks1;
}
public static void effectBlackHoleBlock(Player zhubo){
Region region = game.getRegion();
Location location = zhubo.getLocation();
List<FallingBlock> fallingBlocks = new ArrayList<>();
AtomicBoolean stop = new AtomicBoolean(false);
new BukkitRunnable() {
private int i = 0;
@Override
public void run() {
if (i >= 5) {
Bukkit.getScheduler().runTaskLater(Main.plugin, ()-> {
stop.set(true);
fallingBlocks.forEach(fallingBlock -> fallingBlock.setGravity(true));
location.getWorld().createExplosion(location, 3.0F, false, false);
}, 20L);
cancel();
return;
}
Set<Block> blocks = getRandomUpBlocks(region, 100);
for (Block block : blocks) {
FallingBlock fallingBlock = region.getWorld().spawnFallingBlock(block.getLocation().add(0.5, 0, 0.5), block.getBlockData());
fallingBlock.setDropItem(false);
fallingBlock.setHurtEntities(false);
fallingBlock.setGravity(false);
block.setType(Material.AIR);
fallingBlocks.add(fallingBlock);
}
i++;
}
}.runTaskTimer(Main.plugin, 0L, 10L);
new BukkitRunnable() {
private Set<UUID> uuids = new HashSet<>();
@Override
public void run() {
if (stop.get()) {
cancel();
return;
}
Iterator<FallingBlock> iterator = fallingBlocks.iterator();
while (iterator.hasNext()) {
FallingBlock fallingBlock = iterator.next();
Vector vector = fallingBlock.getLocation().toVector();
Vector vector1 = location.toVector();
Vector vector2 = vector1.subtract(vector);
vector2.normalize();
vector2.multiply(0.65);
fallingBlock.setVelocity(vector2);
if (!uuids.contains(fallingBlock.getUniqueId())) {
if (RandomUtil.random(0.5)) {
uuids.add(fallingBlock.getUniqueId());
} else {
fallingBlock.remove();
iterator.remove();
}
}
}
}
}.runTaskTimer(Main.plugin, 0L, 1L);
}
public static void effectJumpSkyTnt(Player zhubo,long seconds){
if(!game.isStarted()){return;}
UUID uuid = zhubo.getUniqueId();
String cdKey = "skyTnt";
long timeMilli = CDTimeAPI.getCD(uuid,cdKey);
if(timeMilli >= 1){
CDTimeAPI.setPlayerCD(uuid,cdKey,timeMilli + (1000*seconds));
}else{
CDTimeAPI.setPlayerCD(uuid,cdKey,1000 * seconds);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Vector launchVector = new Vector(0, 1, 0);
zhubo.setVelocity(launchVector);
},2L);
}
}

View File

@ -0,0 +1,233 @@
package me.Demon.BlockWars.Game;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.*;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
public abstract class EffectTnt {
public static GameData game = Main.gameData;
public static void effect_jump_tnt(Player zhubo) {
zhubo.setVelocity(zhubo.getLocation().getDirection().multiply(0.5).setY(1.0));
zhubo.playEffect(zhubo.getLocation(), Effect.MOBSPAWNER_FLAMES, 10);
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1.0F, 1.0F);
BukkitTask task = new BukkitRunnable() {
private int i= 0;
@Override
public void run() {
if(i >= 6){cancel();}
Location location = zhubo.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);
}
public static void spawnTNT(Location location, int fuseTick,float Yield) {
Location newTnt_loc = location.add(0,RandomUtil.getRandomInt(-2,2),0);
TNTPrimed tntPrimed = (TNTPrimed) game.getRegion().getWorld().spawnEntity(newTnt_loc, EntityType.PRIMED_TNT);
tntPrimed.setFuseTicks(fuseTick);
tntPrimed.setYield(Yield);
if(fuseTick == 35) {
if (RandomUtil.getRandomInt(1, 100) >= 70) {
tntPrimed.setVelocity(new Vector(RandomUtil.getRandomDouble(-1, 1, 2), RandomUtil.getRandomDouble(0, 1, 2), RandomUtil.getRandomDouble(-1, 1, 2)));
}
}
location.getWorld().playSound(newTnt_loc, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f);
}
public static void callPlayerTntDrop(Player player,int amount) {
boolean check_loc = false;
if (game.getRegion().isRegionTNTAppearance(player.getLocation())) {
check_loc = true;
}
if(amount >= 1000){
if (check_loc) {
for (int i = 0; i < 30; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
for (int x = 0; x < 15; x++) {
Vector launchVector = new Vector(RandomUtil.getRandomDouble(-1, 1, 1), RandomUtil.getRandomDouble(-2, 0.2, 1), RandomUtil.getRandomDouble(-1, 1, 1));
Location location = player.getLocation().clone();
TNTPrimed tntPrimed = (TNTPrimed) player.getWorld().spawnEntity(location, EntityType.PRIMED_TNT);
tntPrimed.setFuseTicks(20);
tntPrimed.setYield(2.5F);
tntPrimed.setVelocity(launchVector);
location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f);
}
player.playSound(player.getLocation(), "jujueno", 1.0F, 1.0F);
}, (long) i * 5);
}
}else {
callForBombDrops(player, amount);
}
} else {
if (check_loc) {
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Location location = player.getLocation().clone();
TNTPrimed tntPrimed = (TNTPrimed) player.getWorld().spawnEntity(location.add(0, 0.2, 0), EntityType.PRIMED_TNT);
tntPrimed.setFuseTicks(40);
tntPrimed.setYield(2.0F);
tntPrimed.setVelocity(location.getDirection().multiply(0.6D).setY(-0.05));
location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f);
}, (long) i * 2);
}
} else {
callForBombDrops(player, amount);
}
}
}
public static void callForBombDrops(Player zhubo, int amount) {
if (!game.isStarted()) {return;}
Region region = game.getRegion();
int y = (int) (Math.round(region.getMax().getY()) + RandomUtil.getRandomInt(1,10));
if(amount <= 1){
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, 60,2.5F);
} else if(amount >= 5000) {
// 获取掉落次数
int max_kongtou = 100;
// 获取每次掉落数量
int kongtou_tnt = (int) (amount / max_kongtou * 0.7);
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
} else if(amount >= 200) {
// 获取掉落次数
int max_kongtou = 8 + (amount / 100);
// 获取每次掉落数量
int kongtou_tnt = (int) (amount / max_kongtou * 0.7);
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
}else if(amount >= 150) {
// 获取掉落次数
int max_kongtou = 8;
// 获取每次掉落数量
int kongtou_tnt = 13;
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
}else if(amount >= 100) {
// 获取掉落次数
int max_kongtou = 8;
// 获取每次掉落数量
int kongtou_tnt = 11;
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
}else if(amount >= 90) {
// 获取掉落次数
int max_kongtou = 6;
// 获取每次掉落数量
int kongtou_tnt = 12;
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
}else if(amount >= 50) {
// 获取掉落次数
int max_kongtou = 5;
// 获取每次掉落数量
int kongtou_tnt = 8;
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location, RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
}else if(amount >= 20) {
// 获取掉落次数
int max_kongtou = 4;
// 获取每次掉落数量
int kongtou_tnt = 4;
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location,RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
} else if(amount >= 10) {
// 获取掉落次数
int max_kongtou = 3;
// 获取每次掉落数量
int kongtou_tnt = 3;
for (int k = 0; k < max_kongtou; k++) {
BukkitTask task = Bukkit.getScheduler().runTaskLater(Main.plugin, ()->{
for (int i = 0; i < kongtou_tnt; i++) {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() -1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location,RandomUtil.getRandomInt(30,70),2.5F);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, RandomUtil.getRandomInt(1,10), 1.1, 1.1, 1.1, 0.35);
}
}, (long) k * 8);
game.addTasks(task);
}
} else {
for (int i = 0; i < amount; i++) {
long delay = 1 + (i * 3L);
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
Location location = RandomUtil.getRandomLocation(zhubo,region.getWorld(), region.getMin().getX() + 1, region.getMax().getX() - 1, y, y, region.getMin().getZ() + 1, region.getMax().getZ() - 1);
spawnTNT(location,RandomUtil.getRandomInt(30,70), 2.5F);
location.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 10, 0.85, 0.85, 0.85, 0.02);
}
}.runTaskLater(Main.plugin, delay);
game.addTasks(task);
}
}
}
}

View File

@ -41,6 +41,7 @@ public class GameData {
private List<BlockRegion> blockRegionList = new ArrayList<>();
private int totalBlockAmount = 0; // 当前矿坑中的方块数量
private int completeBlockGoal = 0;
private List<BukkitTask> gameTask = new ArrayList<>();
private List<BukkitTask> tasks = new ArrayList<>();
private boolean checking; // 挑战成功
private int countdownTime = 15; // 挑战成功倒计时
@ -55,6 +56,7 @@ public class GameData {
public void updateBossBar(){
refreshCompleteBossBar();
refreshGiveALikeEffect();
refreshDianZanBossBar();
}
// 刷新今日挑战进度
@ -70,17 +72,54 @@ public class GameData {
BossBarUtil.setBarProgress(bossBar1,percent);
BossBarUtil.setBarColor(bossBar1,percent);
}
// 刷新点赞掉炸弹进度
public void refreshDianZanBossBar() {
int dz = Main.configYml.getDianzan_amount();
int dz_need = Main.configYml.getDianzan_need();
double dz1 = (double) dz / (double) dz_need;
bossBar3.setTitle("§6掉炸弹: §d"+dz+"§f/§c"+dz_need);
if(dz >= 10){
bossBar3.setStyle(BarStyle.SEGMENTED_10);
}else {
bossBar3.setStyle(BarStyle.SOLID);
}
if(dz1 <= 0){
dz1 = 0;
}else if(dz1 >= 1){
dz1 = 1;
}
BossBarUtil.setBarProgress(bossBar3,dz1);
BossBarUtil.setBarColor(bossBar3,dz1);
}
public void refreshGiveALikeEffect(){
int a = this.totalBlockAmount;
int b = this.completeBlockGoal;
double percent = (double) a / (double) b;
// System.out.println("[调试 - 进度] 填充进度: "+a+" b = "+b);
String percentShow = String.format("%.2f", (percent * 100));
bossBar2.setTitle("§6填充进度: §f"+a+"/"+b+" §9("+percentShow+"%)");
// System.out.println("[调试 - 进度] 填充进度: "+percent);
BossBarUtil.setBarProgress(bossBar2,percent);
BossBarUtil.setBarColor(bossBar2,percent);
int block = this.completeBlockGoal;
String percentShow = "§f"+block;
if (block >= 1000000) { // 1亿
int yi = block / 1000000;
int rest = block % 1000000;
percentShow = "§f" + yi + "§c百万";
if (rest > 0) {
int wan = rest / 10000;
int restWan = rest % 10000;
if (wan > 0) {
percentShow += "§f" + wan + "§c万";
}
if (restWan > 0) {
percentShow += "§f" + restWan;
}
}
} else if (block >= 10000) { // 1万
int wan = block / 10000;
int rest = block % 10000;
percentShow = "§f" + wan + "§c万";
if (rest > 0) {
percentShow += "§f" + rest;
}
}
bossBar2.setTitle("§6填充区域大小: §f"+percentShow+"§c方块");
BossBarUtil.setBarProgress(bossBar2,1.0);
BossBarUtil.setBarColor(bossBar2);
}
public void startGame(){
@ -91,27 +130,44 @@ public class GameData {
for (Player player : Bukkit.getOnlinePlayers()) {
initializePlayerData(player); // 初始化玩家数据
}
tasks.add(new BukkitRunnable() {
@Override
public void run() {
try {
totalBlockAmount = ComputeBlock.getCompleteBlockAmount(blockRegionList).get(); // 每秒刷新一次矿区方块数量
} catch (Exception e) {
e.printStackTrace();
}
}
}.runTaskTimerAsynchronously(Main.plugin, 0L, 20L));
// 初始化主播参数
tasks.add(new BukkitRunnable() {
gameTask.add(new BukkitRunnable() {
@Override
public void run() {
updateBossBar();
if (!checking) {
if(completeBlockGoal < 100000){
refreshTheNonBlankBlockOfMiningArea();
}
checkComplete(); // 检测玩家当前挑战完成进度
}else{
refreshTheNonBlankBlockOfMiningArea();
}
}
}.runTaskTimer(Main.plugin, 0L, 20L));
}
public void refreshTheNonBlankBlockOfMiningArea(){
long startTime = System.currentTimeMillis(); // 记录开始时间
int i = 0;
for (int y = (int) Math.floor(region.getMin().getY()); y <= region.getMax().getY(); y++) {
for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) {
for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) {
Block block = region.getWorld().getBlockAt(x, y, z);
if (!block.getType().equals(Material.AIR)) {
i++;
}
}
}
}
this.totalBlockAmount = i;
if(Main.Debug){
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 获取] 本次获取总数总计耗时 " + duration + " ms");
}
}
public void initializeGameData(){
String worldName = "world";
this.world = Bukkit.getWorld(worldName);
@ -124,10 +180,9 @@ public class GameData {
}
GameGoalAPI.setNowCompleteAmount(0); // 初始化游戏进度
this.checking = false;
GameUtil.loadSchematics("miner_11x11"); // 初始化矿区模板
MinerOperate.initializeMinerSize(); // 初始化矿区大小
updateBossBar();
refreshBlockRgionList(16); // 拆分矿区
refreshBlockRgionList(32); // 拆分矿区
}
/*
* 初始化主播游戏参数: 生命值物品栏BossBar当前位置
@ -140,7 +195,7 @@ public class GameData {
}
player.teleport(region.getHub());
// 添加boss血条
BossBarUtil.addBossBar(player,new ArrayList<>(Arrays.asList(bossBar1,bossBar2)));
BossBarUtil.addBossBar(player,new ArrayList<>(Arrays.asList(bossBar1,bossBar3,bossBar2)));
}
private int countdown; // 当前倒计时
@ -281,30 +336,54 @@ public class GameData {
return BLOCK_TYPES[level];
}
// 增加完成次数
public void effect_addComplete(int a){
if (!started) {
return;
}
int win = GameGoalAPI.getNowcompleteAmount(); // 当前已完成挑战次数
win = win + a;
GameGoalAPI.setNowCompleteAmount(win);
}
// 扣除完成次数
public void effect_takeComplete(int a) {
if (!started) {
return;
}
int win = GameGoalAPI.getNowcompleteAmount();
win = win - a;
GameGoalAPI.setNowCompleteAmount(win);
}
public List<BlockRegion> getBlockRegionList() {
return blockRegionList;
}
public Region getRegion() {
return region;
}
public void setRegion(Region region) {
this.region = region;
setCompleteBlockGoal(ComputeBlock.getCompleteBlockGoal(region));
}
public World getWorld() {
return world;
}
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
GameData.started = started;
}
public void setCompleteBlockGoal(int completeBlockGoal) {
this.completeBlockGoal = completeBlockGoal;
}
public List<BukkitTask> getTasks() {
return tasks;
}
public void addTasks(BukkitTask task){
this.tasks.add(task);
}
public int getTotalBlockAmount() {
return totalBlockAmount;
}
}

View File

@ -106,5 +106,15 @@ public class Region {
&& location.getBlockZ() >= this.min.getZ()
&& location.getBlockZ() <= this.max.getZ());
}
public boolean isRegionTNTAppearance(Location location) {
if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) {
return false;
}
return (location.getBlockX() >= (this.min.getX()+2)
&& location.getBlockX() <= (this.max.getX()-2)
&& location.getBlockY() >= this.min.getY()
&& location.getBlockZ() >= (this.min.getZ()+2)
&& location.getBlockZ() <= (this.max.getZ()-2));
}
}

View File

@ -0,0 +1,118 @@
package me.Demon.BlockWars.Listener;
import cn.hamster3.cdapi.CDTimeAPI;
import me.Demon.BlockWars.Game.EffectTnt;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.RandomUtil;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.UUID;
public class GameEffect implements Listener {
public static int skyTnt = 0;
public static int skyTntSound = 0;
@EventHandler
public void onQuitRemoveEffect(PlayerQuitEvent e){
Player p = e.getPlayer();
CDTimeAPI.setPlayerCD(p.getUniqueId(),"skyTnt",500);
CDTimeAPI.setPlayerCD(p.getUniqueId(),"move_remove_block",500);
}
@EventHandler
public void onplace(PlayerMoveEvent e) {
Player p = e.getPlayer();
UUID uuid = p.getUniqueId();
Location loc = p.getLocation();
if(CDTimeAPI.getCD(uuid,"skyTnt") >= 1){
long milliseconds = CDTimeAPI.getCD(uuid, "skyTnt");
double seconds = (double) milliseconds / 1000;
String message = "§6螺旋升天倒计时: §b" + String.format("%.1f", seconds) + "";
p.sendTitle("§c§l"+String.format("%.1f",p.getLocation().getY())+"","§e当前海拔高度",0,25,5);
p.spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(message));
String skyTntCdKey = "skyTntCd";
long skyTntCd = CDTimeAPI.getCD(uuid,skyTntCdKey);
if(skyTntCd < 1) {
CDTimeAPI.setPlayerCD(uuid,skyTntCdKey,250);
new BukkitRunnable() {
public void run() {
double radius = 1.0;
double angleStep = Math.PI / 4;
double angle = skyTnt * angleStep;
Vector vector = new Vector(radius * Math.cos(angle), 0.5, radius * Math.sin(angle));
p.setVelocity(vector);
skyTnt++;
skyTntSound++;
if (skyTnt >= 8) {
skyTnt = 0;
}
if (skyTntSound >= 10) {
skyTntSound = 0;
p.playSound(p.getLocation(),"dxj",1,1);
}
cancel();
}
}.runTaskLater(Main.plugin, 5L);
}
new BukkitRunnable() {
public void run() {
EffectTnt.spawnTNT(p.getLocation().add(0, -1.3D, 0), 50, 4);
cancel();
}
}.runTaskLater(Main.plugin, 10L);
}
}
@EventHandler
public void onMove(PlayerMoveEvent e){
Player p = e.getPlayer();
UUID uuid = p.getUniqueId();
Location loc = p.getLocation();
World world = loc.getWorld();
if(CDTimeAPI.getCD(uuid,"move_remove_block") >= 1) {
if (CDTimeAPI.getCD(uuid, "move_kk_cd") >= 1) {
return;
}
if(p.isFlying()) {
p.setFlying(false);
}
if(!Main.gameData.getRegion().isInRegionPlayer(loc)){
p.teleport(Main.gameData.getRegion().getHub().add(0,-2,0));
}
p.playSound(p.getLocation(),"ji",0.5F,1);
long milliseconds = CDTimeAPI.getCD(uuid, "move_remove_block");
double seconds = (double) milliseconds / 1000;
Vector launchVector = new Vector(RandomUtil.getRandomDouble(-1, 1, 1), 0, RandomUtil.getRandomDouble(-1, 1, 1));
p.setVelocity(launchVector);
String message = "§6坤坤冲击倒计时: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(message));
CDTimeAPI.setPlayerCD(uuid, "move_kk_cd", 100);
world.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 10);
// 清理3x3区域的方块
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 2; y++) {
for (int z = -1; z <= 1; z++) {
Block block = world.getBlockAt(loc.clone().add(x,y,z));
if (Main.gameData.getRegion().isInRegion(block.getLocation())) {
block.setType(org.bukkit.Material.AIR);
}
}
}
}
}
}
}

View File

@ -1,6 +1,7 @@
package me.Demon.BlockWars.Listener;
import cn.hamster3.cdapi.CDTimeAPI;
import me.Demon.BlockWars.Data.RepairGiftGui;
import me.Demon.BlockWars.Game.Region;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.GameUtil;
@ -69,11 +70,9 @@ public class GameListener implements Listener {
Player p = e.getPlayer();
if (Main.gameData.isStarted()) {
if(p.isSneaking()){
// RepairGiftGui.OpenGui(p);
RepairGiftGui.OpenGui(p);
} else {
if (p.getGameMode() == GameMode.CREATIVE) {
p.setGameMode(GameMode.SPECTATOR);
}
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
}
e.setCancelled(true);
}
@ -197,9 +196,11 @@ public class GameListener implements Listener {
a++;
}
GameUtil.refreshPlayerHandStack(p);
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 快速] 本次搭建总计耗时 " + duration + " ms");
if (Main.Debug) {
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 快速] 本次搭建总计耗时 " + duration + " ms");
}
}else{
if(sounds_butt) {
p.playSound(p.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_PLACE, 1.0F, 1.0F);

View File

@ -1,16 +0,0 @@
package me.Demon.BlockWars.Listener;
import me.Demon.BlockWars.Eventi.MinerChangeEvent;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Main;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class MinerChange implements Listener {
@EventHandler
public void onChange(MinerChangeEvent e){
GameData gameData = e.getGame();
gameData.refreshBlockRgionList(16);
}
}

View File

@ -0,0 +1,260 @@
package me.Demon.BlockWars.LiveEvent;
import cn.hamster3.cdapi.CDTimeAPI;
import com.yaohun.bwaddon.api.ExtendAPI;
import me.Demon.BlockWars.Game.EffectEntity;
import me.Demon.BlockWars.Game.EffectTime;
import me.Demon.BlockWars.Game.EffectTnt;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Manager.MinerOperate;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.Util.RandomUtil;
import me.Demon.BlockWars.api.ExtendEffectAPI;
import org.bukkit.Bukkit;
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
public class GiftEventHandler {
public static void SendHandLer(Player zhubo,String userName,String eventName){
GameData game = Main.gameData;
userName = GameUtil.HideName(userName);
if (eventName.equalsIgnoreCase("炸弹")) {
EffectTnt.callPlayerTntDrop(zhubo,1);
zhubo.playSound(zhubo.getLocation(),"jujueno",1.0F,1.0F);
} else if (eventName.contains("炸弹X")) {
String[] eventSp = eventName.split("X");
int amount = Integer.parseInt(eventSp[1]);
EffectTnt.callPlayerTntDrop(zhubo,amount);
} else if (eventName.contains("TNTX")) {
String[] eventSp = eventName.split("X");
int amount = Integer.parseInt(eventSp[1]);
EffectTnt.callPlayerTntDrop(zhubo,amount);
} else if (eventName.equalsIgnoreCase("小雷王")) {
EffectTnt.callPlayerTntDrop(zhubo,1);
}else if (eventName.equalsIgnoreCase("三响炮")) {
EffectTnt.callPlayerTntDrop(zhubo,3);
} else if (eventName.equalsIgnoreCase("TNT10")) {
EffectTnt.callPlayerTntDrop(zhubo,10);
} else if (eventName.equalsIgnoreCase("TNT100")) {
EffectTnt.callPlayerTntDrop(zhubo,100);
} else if (eventName.equalsIgnoreCase("TNT1000")) {
EffectTnt.callPlayerTntDrop(zhubo,1000);
} else if (eventName.equalsIgnoreCase("TNT99999")) {
EffectTnt.callForBombDrops(zhubo,5500);
EffectTime.effectJumpSkyTnt(zhubo, 40);
} else if (eventName.equalsIgnoreCase("TNT120")) {
EffectTnt.callForBombDrops(zhubo,120);
} else if (eventName.equalsIgnoreCase("TNT150")) {
EffectTnt.callForBombDrops(zhubo,150);
} else if (eventName.equalsIgnoreCase("TNT200")) {
EffectTnt.callForBombDrops(zhubo,200);
} else if (eventName.equalsIgnoreCase("TNT300")) {
EffectTnt.callForBombDrops(zhubo,300);
} else if (eventName.equalsIgnoreCase("TNT500")) {
EffectTnt.callForBombDrops(zhubo,500);
} else if (eventName.equalsIgnoreCase("TNT520")) {
EffectTnt.callForBombDrops(zhubo,520);
} else if (eventName.equalsIgnoreCase("TNT1200")) {
EffectTnt.callForBombDrops(zhubo,1200);
} else if (eventName.equalsIgnoreCase("TNT1600")) {
EffectTnt.callForBombDrops(zhubo,1600);
} else if (eventName.equalsIgnoreCase("TNT2000")) {
EffectTnt.callForBombDrops(zhubo,2000);
} else if (eventName.equalsIgnoreCase("TNT3200")) {
EffectTnt.callForBombDrops(zhubo,2500);
} else if (eventName.equalsIgnoreCase("TNT5000")) {
EffectTnt.callForBombDrops(zhubo,4000);
} else if (eventName.equalsIgnoreCase("修复一层")) {
MinerOperate.repairBlock();
} else if (eventName.equalsIgnoreCase("修复三层")) {
for (int i = 0; i < 3;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},35L);
} else if (eventName.equalsIgnoreCase("修复九层")) {
for (int i = 0; i < 9;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},95L);
} else if (eventName.equalsIgnoreCase("修复10层")) {
for (int i = 0; i < 10;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},105L);
}else if (eventName.equalsIgnoreCase("修复15层")) {
for (int i = 0; i < 10;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},105L);
}else if (eventName.equalsIgnoreCase("修复20层")) {
for (int i = 0; i < 20;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},205L);
}else if (eventName.equalsIgnoreCase("修复25层")) {
for (int i = 0; i < 25;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},255L);
}else if (eventName.equalsIgnoreCase("修复30层")) {
for (int i = 0; i < 30;i++){
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
MinerOperate.repairBlock();
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
},i*10L);
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},305L);
} else if (eventName.equalsIgnoreCase("修复全部")) {
MinerOperate.fillMinerAll(game.getBlockRegionList());
} else if (eventName.equalsIgnoreCase("清空砖块") || eventName.equalsIgnoreCase("别玩了吧") || eventName.equalsIgnoreCase("清空所有")) {
MinerOperate.clearMinerAll(game.getBlockRegionList());
} else if (eventName.equalsIgnoreCase("大风车")) {
EffectEntity.effect_Rotate_360(zhubo);
} else if (eventName.equalsIgnoreCase("重置矿区") || eventName.equalsIgnoreCase("场地重置")|| eventName.equalsIgnoreCase("矿区重置")) {
ExtendEffectAPI.resetMinerSize();
new BukkitRunnable() {
@Override
public void run() {
MinerOperate.initializeMinerSize();
zhubo.teleport(game.getRegion().getHub());
}
}.runTaskLater(Main.plugin,20L);
} else if (eventName.equalsIgnoreCase("黑洞")) {
EffectTime.effectBlackHoleBlock(zhubo);
} else if (eventName.equalsIgnoreCase("完成一局")) {
game.effect_addComplete(1);
}else if (eventName.contains("完成加")) {
String[] eventSp = eventName.split("");
int amount = getChainAmount(eventSp[1]);
game.effect_addComplete(amount);
zhubo.playEffect(EntityEffect.TOTEM_RESURRECT);
zhubo.getWorld().strikeLightningEffect(zhubo.getLocation());
zhubo.playSound(zhubo.getLocation(),"waou",1.0F,1.0F);
}else if (eventName.contains("完成减")) {
String[] eventSp = eventName.split("");
int amount = getChainAmount(eventSp[1]);
game.effect_takeComplete(amount);
zhubo.playEffect(EntityEffect.TOTEM_RESURRECT);
zhubo.getWorld().strikeLightningEffect(zhubo.getLocation());
zhubo.playSound(zhubo.getLocation(),"waou",1.0F,1.0F);
}else if (eventName.equalsIgnoreCase("精神攻击")) {
int random_int = RandomUtil.getRandomInt(0,100);
if(random_int >= 70) {
zhubo.playSound(zhubo.getLocation(), "cf_lailelaodi", 2, 1);
}else if(random_int >= 40){
zhubo.playSound(zhubo.getLocation(), "cf_taixunle", 2, 1);
}else{
zhubo.playSound(zhubo.getLocation(), "cf_xingbuxinga", 5, 1);
}
} else if (eventName.equalsIgnoreCase("螺旋升天")) {
EffectTime.effectJumpSkyTnt(zhubo, 10);
zhubo.playSound(zhubo.getLocation(),"dxj",1,1);
} else if (eventName.equalsIgnoreCase("芜湖起飞")) {
EffectTnt.effect_jump_tnt(zhubo);
} else if (eventName.equalsIgnoreCase("坤坤冲击")) {
EffectTime.effect_moveBlock(zhubo);
}else if (eventName.contains("猪猪X")) {
String[] eventSp = eventName.split("X");
int amount = Integer.parseInt(eventSp[1]);
EffectEntity.effect_spawn_pig(zhubo,userName,amount);
}else if (eventName.equalsIgnoreCase("猪猪来咯")) {
EffectEntity.effect_spawn_pig(zhubo,userName,2);
}else if (eventName.equalsIgnoreCase("猪猪")) {
EffectEntity.effect_spawn_pig(zhubo,userName,1);
}else if (eventName.contains("小绿人X")) {
String[] eventSp = eventName.split("X");
int amount = Integer.parseInt(eventSp[1]);
EffectEntity.effect_spawn_Zombie(zhubo,userName,amount);
}else if (eventName.contains("钢铁人X")) {
String[] eventSp = eventName.split("X");
int amount = Integer.parseInt(eventSp[1]);
EffectEntity.effect_spawn_IronGolem(zhubo,userName,amount);
}else{
Bukkit.broadcastMessage("§c[系统]§a触发效果 §e"+eventName+" §a不存在.");
}
}
private static final Map<String, Integer> amountMap = new HashMap<>();
static {
amountMap.put("", 1);
amountMap.put("", 2);
amountMap.put("", 3);
amountMap.put("", 4);
amountMap.put("", 5);
amountMap.put("", 6);
amountMap.put("", 7);
amountMap.put("", 8);
amountMap.put("", 9);
amountMap.put("", 10);
amountMap.put("十一", 11);
amountMap.put("十二", 12);
amountMap.put("十三", 13);
amountMap.put("十四", 14);
amountMap.put("十五", 15);
amountMap.put("十六", 16);
amountMap.put("十七", 17);
amountMap.put("十八", 18);
amountMap.put("十九", 19);
amountMap.put("二十", 20);
}
public static int getChainAmount(String amountKey) {
return amountMap.getOrDefault(amountKey, 1);
}
}

View File

@ -0,0 +1,69 @@
package me.Demon.BlockWars.LiveEvent;
import com.io.yutian.mclive.event.LiveGiftEvents;
import com.yaohun.RandomBox.api.RBoxAPI;
import com.yaohun.bwaddon.api.ExtendAPI;
import me.Demon.BlockWars.Data.GiftData;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.ConfigYml;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class GiftListener implements Listener {
@EventHandler
public void onGfit(LiveGiftEvents e) {
Player zhubo = e.getPlayer();
String userName = ""+ RandomUtil.getRandomInt(999,10000);
boolean butt = false;
if(e.getUser().nickName() != null) {
userName = e.getUser().nickName();
butt = true;
}
String giftName = e.getName();
int amount = (int) e.getAmount();
if (amount <= 0) {
amount = 1;
}
ConfigYml configYml = Main.configYml;
if(configYml.getGiftData(giftName) == null){
return;
}
GiftData giftData = configYml.getGiftData(giftName);
giftData.OutCompleEvent(amount);
String show_userName = GameUtil.HideName(userName);
for (Player player : Bukkit.getOnlinePlayers()){
player.sendMessage("§a礼物: §e"+show_userName+" §d送来了 §e"+giftName+"x"+amount);
}
String eventName = giftData.getEvent();
if(GameUtil.specialGiftEffectTriggers(zhubo,eventName,show_userName,amount)){
return;
}
String title = "§c" + eventName;
if(amount >= 2) {
title = "§c" + eventName + " x" + amount;
}
String subtitle = "§9" + giftName;
if(butt) {
subtitle = "§9" + show_userName;
}
zhubo.sendTitle(title, subtitle,0, 30, 10);
if (amount <= 1) {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, userName, eventName);
} else {
long dadey = 5L;
for (int i = 0; i < amount; i++) {
String finalUserName = userName;
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, finalUserName, eventName);
}, (long) i * dadey);
}
}
}
}

View File

@ -0,0 +1,33 @@
package me.Demon.BlockWars.LiveEvent;
import com.io.yutian.mclive.event.LiveLikeEvents;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.ConfigYml;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class LikeListener implements Listener {
@EventHandler//点赞
public void onDianZan(LiveLikeEvents e) {
Player zhubo = e.getPlayer();
String userName = ""+ RandomUtil.getRandomInt(999,10000);
if(e.getUser().nickName() != null) {
userName = e.getUser().nickName();
}
long add_amount = e.getCount();
if(GameUtil.isAntiGiftEvent()){return;}
ConfigYml configYml = Main.configYml;
configYml.addDianzan_amount((int) add_amount);
if (configYml.getDianzan_amount() >= configYml.getDianzan_need()) {
String eventName_Show = configYml.getDianzan_event();
String title = "§c"+eventName_Show;
String subtitle = "§9双击屏幕x"+configYml.getDianzan_need();
zhubo.sendTitle(title, subtitle,10, 30, 10);
GiftEventHandler.SendHandLer(zhubo,userName,configYml.getDianzan_event());
configYml.setDianzan_amount(0);
}
}
}

View File

@ -1,45 +1,112 @@
package me.Demon.BlockWars;
import me.Demon.BlockWars.Data.RepairGiftGui;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Listener.GameListener;
import me.Demon.BlockWars.Listener.GamePotect;
import me.Demon.BlockWars.Listener.JoinEvent;
import me.Demon.BlockWars.Listener.MinerChange;
import me.Demon.BlockWars.Listener.*;
import me.Demon.BlockWars.LiveEvent.GiftEventHandler;
import me.Demon.BlockWars.LiveEvent.GiftListener;
import me.Demon.BlockWars.LiveEvent.LikeListener;
import me.Demon.BlockWars.Manager.MinerOperate;
import me.Demon.BlockWars.Util.ComputeBlock;
import me.Demon.BlockWars.Util.ConfigYml;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Main extends JavaPlugin {
public static boolean Debug = false;
public static Main plugin;
public static GameData gameData;
public static ConfigYml configYml;
public static FileConfiguration giftYml;
@Override
public void onEnable() {
plugin = this;
File file = new File("./plugins/游戏设置","礼物设置.yml");
giftYml = YamlConfiguration.loadConfiguration(file);
saveDefaultConfig();
configYml = new ConfigYml();
gameData = new GameData();
getServer().getPluginManager().registerEvents(new JoinEvent(),this);
getServer().getPluginManager().registerEvents(new MinerChange(),this);
getServer().getPluginManager().registerEvents(new GamePotect(),this);
getServer().getPluginManager().registerEvents(new GameListener(),this);
getServer().getPluginManager().registerEvents(new GameEffect(),this);
getServer().getPluginManager().registerEvents(new GiftListener(),this);
getServer().getPluginManager().registerEvents(new LikeListener(),this);
getServer().getPluginManager().registerEvents(new RepairGiftGui(),this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String Command, String[] args) {
if (Command.equalsIgnoreCase("game")) {
if(args[0].equalsIgnoreCase("test1")){
MinerOperate.clearMinerAll(Main.gameData.getBlockRegionList());
if (Command.equalsIgnoreCase("livegift")) {
RepairGiftGui.OpenGui((Player) sender);
return true;
}
if (Command.equalsIgnoreCase("game") || Command.equalsIgnoreCase("bw")) {
if (args.length == 0) {
sender.sendMessage("");
sender.sendMessage("§e------ ====== §6TNT炸弹填充 §e====== ------");
sender.sendMessage("§2/"+Command+" add §e[数量] §f- §2增加成功次数");
sender.sendMessage("§2/"+Command+" take §e[数量] §f- §2减少成功次数");
sender.sendMessage("§e------ ====== §6TNT炸弹填充 §e====== ------");
sender.sendMessage("");
return true;
}
if(args[0].equalsIgnoreCase("test2")){
MinerOperate.fillMinerAll(Main.gameData.getBlockRegionList());
if(args.length == 1 && args[0].equalsIgnoreCase("add")){
if (!Main.gameData.isStarted()) {
return true;
}
Main.gameData.effect_addComplete(1);
}
if(args.length == 1 && args[0].equalsIgnoreCase("take")){
if (!Main.gameData.isStarted()) {
return true;
}
Main.gameData.effect_takeComplete(1);
}
if(args.length == 2 && args[0].equalsIgnoreCase("add")){
if (!Main.gameData.isStarted()) {
return true;
}
int amount = Integer.parseInt(args[1]);
Main.gameData.effect_addComplete(amount);
return true;
}
if(args.length == 2 && args[0].equalsIgnoreCase("take")) {
if (!Main.gameData.isStarted()) {
return true;
}
int amount = Integer.parseInt(args[1]);
Main.gameData.effect_takeComplete(amount);
return true;
}
if(args[0].equalsIgnoreCase("updata")){
gameData.setCompleteBlockGoal(ComputeBlock.getCompleteBlockGoal(Main.gameData.getRegion()));
}
if(args.length == 2 && args[0].equalsIgnoreCase("sendevent")){
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
Player player = players.get(0);
if(sender instanceof Player){
player = (Player) sender;
}
String eventName = args[1];
String userName = "观众"+ RandomUtil.getRandomInt(0,10);
String title = "§c" + eventName;
String subtitle = "§9" + GameUtil.HideName(userName);
player.sendTitle(title, subtitle,10, 30, 10);
GiftEventHandler.SendHandLer(player, userName, eventName);
return true;
}
}
return false;

View File

@ -3,6 +3,7 @@ package me.Demon.BlockWars.Manager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import me.Demon.BlockWars.Game.BlockRegion;
import me.Demon.BlockWars.Game.GameData;
@ -10,9 +11,12 @@ import me.Demon.BlockWars.Game.Point;
import me.Demon.BlockWars.Game.Region;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.ComputeBlock;
import me.Demon.BlockWars.Util.GameUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -29,6 +33,7 @@ public abstract class MinerOperate {
GameData gameData = Main.gameData;
Region region = new Region(Bukkit.getWorld("world"),new Point(103,min_minerY,-6),new Point(113, max_minerY, 4));
gameData.setRegion(region);
GameUtil.loadSchematics("miner_11x11"); // 初始化矿区模板
gameData.setCompleteBlockGoal(ComputeBlock.getCompleteBlockGoal(region));
}
public static void clearMinerAll(List<BlockRegion> blockRegionList){
@ -54,6 +59,12 @@ public abstract class MinerOperate {
}
});
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},20L);
}
public static void fillMinerAll(List<BlockRegion> blockRegionList){
@ -79,5 +90,63 @@ public abstract class MinerOperate {
}
});
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(Main.gameData.getRegion().getHub());
}
Main.gameData.refreshTheNonBlankBlockOfMiningArea(); // 刷新矿区当前块数量
},20L);
}
public static void repairBlock(){
long startTime = System.currentTimeMillis(); // 记录开始时间
GameData game = Main.gameData;
Region region = game.getRegion();
boolean ford = false;
Material material = Material.DIAMOND_BLOCK;// 获取当前层数下一层的方块类型
int fillY = (int) region.getMin().getY(); // 获取修复的指定层数
// 通过遍历区域中所有方块获取到高度
for (int y = fillY; y <= region.getMax().getY(); y++) {
if(ford){break;}
for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) {
if(ford){break;}
for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) {
Block block = region.getWorld().getBlockAt(x, y, z);
if (block.getType().equals(Material.AIR)) {
fillY = y;
Block lowerBlock = block.getLocation().add(0,-1,0).getBlock();
material = getMaterial(lowerBlock.getType());
ford = true;
break;
}
}
}
}
BlockVector3 vector1 = BlockVector3.at(region.getMin().getX(), fillY, region.getMin().getZ());
BlockVector3 vector2 = BlockVector3.at(region.getMax().getX(), fillY, region.getMax().getZ());
CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(material));
} catch (Exception e) {
e.printStackTrace();
}
if(Main.Debug) {
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 修复] 本次修复所有总计耗时 " + duration + " ms");
}
}
public static Material getMaterial(Material material){
if(material == Material.IRON_BLOCK) {
return Material.GOLD_BLOCK;
}else if(material == Material.GOLD_BLOCK) {
return Material.DIAMOND_BLOCK;
}else if(material == Material.DIAMOND_BLOCK) {
return Material.EMERALD_BLOCK;
}else if(material == Material.EMERALD_BLOCK) {
return Material.IRON_BLOCK;
}
return Material.IRON_BLOCK;
}
}

View File

@ -8,6 +8,21 @@ import java.util.List;
public class BossBarUtil {
public static void setBarColor(BossBar bossBar){
double random = RandomUtil.getRandomDouble(0,1,1);
if (random >= 0 && random <= 0.2) {
bossBar.setColor(BarColor.RED);
} else if (random <= 0.4) {
bossBar.setColor(BarColor.YELLOW);
} else if (random <= 0.6) {
bossBar.setColor(BarColor.GREEN);
} else if (random <= 0.8) {
bossBar.setColor(BarColor.BLUE);
} else {
bossBar.setColor(BarColor.PURPLE);
}
}
public static void setBarColor(BossBar bossBar,double percent){
if (percent >= 0 && percent <= 0.3333) {
bossBar.setColor(BarColor.RED);

View File

@ -18,7 +18,28 @@ import java.util.concurrent.atomic.AtomicInteger;
public class ComputeBlock {
public static CompletableFuture<Integer> getCompleteBlockAmount(List<BlockRegion> blockRegionList) {
public static int getCompleteBlock(Region region) {
long startTime = System.currentTimeMillis(); // 记录开始时间
int i = 0;
for (int y = (int) Math.floor(region.getMin().getY()); y <= region.getMax().getY(); y++) {
for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) {
for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) {
Block block = region.getWorld().getBlockAt(x, y, z);
if (!block.getType().equals(Material.AIR)) {
i++;
}
}
}
}
if(Main.Debug){
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
System.out.println("[调试 - 获取] 本次获取总数总计耗时 " + duration + " ms");
}
return i;
}
/*public static CompletableFuture<Integer> getCompleteBlockAmount(List<BlockRegion> blockRegionList) {
CompletableFuture completableFuture = CompletableFuture.supplyAsync(()->{
int amount = 0;
for (BlockRegion blockRegion : blockRegionList) {
@ -31,7 +52,6 @@ public class ComputeBlock {
});
return completableFuture;
}
public static int countBlocks(CuboidRegion cuboidRegion) {
World world = Main.gameData.getWorld();
int blockCount = 0;
@ -47,14 +67,13 @@ public class ComputeBlock {
}
return blockCount;
}
*/
public static CuboidRegion getCuboidRegion(int minX, int maxX){
Region region = Main.gameData.getRegion();
BlockVector3 vector1 = BlockVector3.at(minX, region.getMin().getY(), region.getMin().getZ());
BlockVector3 vector2 = BlockVector3.at(maxX, region.getMax().getY(), region.getMax().getZ());
return new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2);
}
/*
* 每次矿区大小发生变化时需要调用一次!!!!
* */

View File

@ -1,74 +1,60 @@
package me.Demon.BlockWars.Util;
import me.Demon.BlockWars.Data.GiftData;
import me.Demon.BlockWars.Main;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ConfigYml {
private String minersize;
private int countdownTime;
private int circularMax;
private int heightMax;
private int completeAmount;
private int dianzan_amount;
private int dianzan_need;
private String dianzan_event;
private HashMap<String,List<String>> randonBoxList = new HashMap<>();
private HashMap<String, Integer> gameSettings = new HashMap<>();
private HashMap<String, GiftData> giftData = new HashMap<>();
public ConfigYml(){
this.dianzan_amount = 0;
FileConfiguration settings_yml = Main.plugin.getConfig();
this.minersize = settings_yml.getString("minersize");
this.circularMax = settings_yml.getInt("circularMax");
this.heightMax = settings_yml.getInt("heightMax");
this.completeAmount = settings_yml.getInt("completeAmount");
this.countdownTime = settings_yml.getInt("countdownTime");
Bukkit.getConsoleSender().sendMessage("[日志 - 炸弹填充] 游戏设置:");
if(settings_yml.getConfigurationSection("Settings") != null){
Bukkit.getConsoleSender().sendMessage("设置: 最大圈数 "+this.circularMax+"");
Bukkit.getConsoleSender().sendMessage("设置: 最大高度 "+this.heightMax+"");
for (String buttKey : settings_yml.getConfigurationSection("Settings").getKeys(false)){
int settings_type = settings_yml.getInt("Settings."+buttKey);
gameSettings.put(buttKey, settings_type);
Bukkit.getConsoleSender().sendMessage("设置: "+buttKey+" "+getSwitchString(settings_type));
}
}
// 注册直播互动事件
FileConfiguration gift_yml = Main.giftYml;
LoadDianEvent(Main.giftYml);
Bukkit.getConsoleSender().sendMessage("[日志 - 炸弹填充] 事件注册:");
if(gift_yml.getConfigurationSection("礼物设置") != null){
Bukkit.getConsoleSender().sendMessage("事件: 盲盒 数量: "+randonBoxList.size()+"");
Bukkit.getConsoleSender().sendMessage("事件: "+this.getDianzan_event()+" 条件: 点赞x"+this.getDianzan_need());
for (String giftName : gift_yml.getConfigurationSection("礼物设置").getKeys(false)){
giftData.put(giftName,new GiftData(giftName,gift_yml));
}
}
}
public void LoadDianEvent(FileConfiguration yml){
this.dianzan_need = 300;
if(yml.getInt("LiveLike.needamount") >= 1){
this.dianzan_need = yml.getInt("LiveLike.needamount");
if(yml.getInt("点赞整蛊.点赞次数") >= 1){
this.dianzan_need = yml.getInt("点赞整蛊.点赞次数");
}
this.dianzan_event = "小雷王";
if(yml.getString("LiveLike.event") != null){
this.dianzan_event = yml.getString("LiveLike.event");
if(yml.getString("点赞整蛊.效果") != null){
this.dianzan_event = yml.getString("点赞整蛊.效果");
}
}
// 保存配置文件
public void SaveSettingsConfig(){
FileConfiguration yml = Main.plugin.getConfig();
yml.set("minersize",this.minersize);
yml.set("completeAmount",this.completeAmount);
yml.set("countdownTime",this.countdownTime);
for (String buttKey : gameSettings.keySet()) {
yml.set("Settings."+buttKey,gameSettings.get(buttKey));
}
Main.plugin.saveConfig();
}
public List<String> getRandonBoxList(String box_type) {
if(this.randonBoxList.get(box_type) != null){
return this.randonBoxList.get(box_type);
}
return new ArrayList<>();
}
public boolean isGameSettings(String buttKey){
if(gameSettings.get(buttKey) != null){
int type = gameSettings.get(buttKey);
@ -118,4 +104,13 @@ public class ConfigYml {
public void setDianzan_amount(int dianzan_amount) {
this.dianzan_amount = dianzan_amount;
}
public GiftData getGiftData(String giftName){
if(this.giftData.get(giftName) != null){
return this.giftData.get(giftName);
}
return null;
}
public HashMap<String, GiftData> getGiftData() {
return giftData;
}
}

View File

@ -6,12 +6,12 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.math.BlockVector3;
import com.yaohun.RandomBox.api.RBoxAPI;
import com.yaohun.bwaddon.api.ExtendAPI;
import me.Demon.BlockWars.Main;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
@ -92,4 +92,98 @@ 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 SendMessage(CommandSender sender, String message){
sender.sendMessage("§c[系统]§a"+message);
}
public static void SendAllSounds(String sound){
for (Player player : Bukkit.getOnlinePlayers()) {
if (sound.contains("_")) {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
} else {
player.playSound(player.getLocation(), sound, 0.5F, 1);
}
}
}
public static boolean specialGiftEffectTriggers(Player player,String eventName,String show_userName,int amount){
if (eventName.contains("盲盒")) {
if(eventName.contains("#")) {
String s1 = "love";
String s2 = "000304";
String box = s1+"-"+s2+"-"+eventName.split("#")[1];
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
RBoxAPI.addUserData(player, show_userName, box, amount);
}else{
System.out.println("[错误 - 盲盒] 随机盲盒在礼物设置中配置错误.");
}
return true;
}else if (eventName.contains("扩建")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName,"向前扩建",amount);
return true;
} else if (eventName.contains("拆迁")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName,"向前拆除",amount);
return true;
} else if (eventName.contains("加宽")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName,"向右扩建",amount);
return true;
} else if (eventName.contains("变窄")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName,"向右拆除",amount);
return true;
} else if (eventName.contains("增高")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName,"向上扩建",amount);
return true;
} else if (eventName.contains("降低")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName, "向上拆除", amount);
return true;
}else if (eventName.contains("扩圈")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName,"扩圈",amount);
return true;
} else if (eventName.contains("缩圈")) {
if(eventName.contains("X")){
amount = Integer.parseInt(eventName.split("X")[1]);
}
ExtendAPI.addUserData(show_userName, "缩圈", amount);
return true;
}
return false;
}
}

View File

@ -0,0 +1,54 @@
package me.Demon.BlockWars.Util;
import com.io.yutian.mclive.event.ZhuboAPI;
import com.yaohun.RandomBox.api.RBoxAPI;
import com.yaohun.bwaddon.api.ExtendAPI;
import me.Demon.BlockWars.Data.GiftData;
import me.Demon.BlockWars.LiveEvent.GiftEventHandler;
import me.Demon.BlockWars.Main;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class GiftUtil {
public static void simulateEventEffect(Player player,String userName, String eventName, int amount){
if (!ZhuboAPI.isWsRoomIdSame(player)) {
player.sendMessage("§c[系统]§a游戏需要连接弹幕抓取软件后才能正常使用此功能.");
return;
}
if(GameUtil.specialGiftEffectTriggers(player,eventName,userName,1)){
return;
}
GiftEventHandler.SendHandLer(player, userName, eventName);
}
public static void simulatedGiftEffect(Player player,String userName, String giftName, int amount){
ConfigYml configYml = Main.configYml;
if(configYml.getGiftData(giftName) == null){
return;
}
if (!ZhuboAPI.isWsRoomIdSame(player)) {
player.sendMessage("§c[系统]§a游戏需要连接弹幕抓取软件后才能正常使用此功能.");
return;
}
GiftData giftData = configYml.getGiftData(giftName);
giftData.OutCompleEvent(amount);
String show_userName = GameUtil.HideName(userName);
String eventName = giftData.getEvent();
if(GameUtil.specialGiftEffectTriggers(player,eventName,show_userName,amount)){
return;
}
if (amount <= 1) {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(player, userName, eventName);
} else {
long dadey = 5L;
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(player, userName, eventName);
}, (long) i * dadey);
}
}
}
}

View File

@ -1,10 +1,21 @@
package me.Demon.BlockWars.api;
import com.yaohun.RandomBox.api.RBoxAPI;
import com.yaohun.bwaddon.api.ExtendAPI;
import me.Demon.BlockWars.Data.GiftData;
import me.Demon.BlockWars.Game.BlockRegion;
import me.Demon.BlockWars.Game.GameData;
import me.Demon.BlockWars.Game.Region;
import me.Demon.BlockWars.LiveEvent.GiftEventHandler;
import me.Demon.BlockWars.Main;
import me.Demon.BlockWars.Util.ConfigYml;
import me.Demon.BlockWars.Util.GameUtil;
import me.Demon.BlockWars.Util.GiftUtil;
import me.Demon.BlockWars.Util.RandomUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class BlockWarsAPI {
@ -22,4 +33,13 @@ public class BlockWarsAPI {
public static List<BlockRegion> getBlockRegionList(){
return getGameData().getBlockRegionList();
}
public static void refreshBlock(){
getGameData().refreshBlockRgionList(32);
}
public static void sendSimulatedGiftEffect(Player player,String userName,String giftName,int amount){
GiftUtil.simulatedGiftEffect(player,userName,giftName,amount);
}
public static void sendSimulateEventEffect(Player player,String userName,String eventName,int amount){
GiftUtil.simulateEventEffect(player,userName,eventName,amount);
}
}

View File

@ -0,0 +1,293 @@
package me.Demon.BlockWars.api;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import me.Demon.BlockWars.Game.Point;
import me.Demon.BlockWars.Game.Region;
import me.Demon.BlockWars.Manager.MinerOperate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
public class ExtendEffectAPI {
public static void rightExpand() {
Point minPoint = BlockWarsAPI.getGameData().getRegion().getMin();
Point maxPoint = BlockWarsAPI.getGameData().getRegion().getMax();
Point newMaxPoint = new Point(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ() + 1);
Region newRegion = new Region(BlockWarsAPI.getGameData().getRegion().getWorld(), minPoint, newMaxPoint);
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld());
com.yaohun.bwaddon.Main.executorService.submit(() -> {
BlockVector3 vector1 = BlockVector3.at(minPoint.getX() - 1, minPoint.getY() - 1, maxPoint.getZ() + 2);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 2);
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
BlockVector3 vector3 = BlockVector3.at(minPoint.getX(), minPoint.getY(), maxPoint.getZ() + 1);
BlockVector3 vector4 = BlockVector3.at(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ() + 2);
CuboidRegion cuboidRegion1 = new CuboidRegion(weWorld, vector3, vector4);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion1, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
});
BlockWarsAPI.getGameData().setRegion(newRegion);
}
/*
* 向右拆除
* */
public static void rightDisassemble() {
Point minPoint = BlockWarsAPI.getGameData().getRegion().getMin();
Point maxPoint = BlockWarsAPI.getGameData().getRegion().getMax();
if(maxPoint.getZ() < -5){
Bukkit.broadcastMessage("§c[消息]§a已经是最窄了!");
return;
}
Point newMaxPoint = new Point(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ() - 1);
Region newRegion = new Region(BlockWarsAPI.getGameData().getRegion().getWorld(), minPoint, newMaxPoint);
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld());
BlockVector3 vector1 = BlockVector3.at(minPoint.getX() - 1, minPoint.getY() - 1, maxPoint.getZ() + 1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 1);
com.yaohun.bwaddon.Main.executorService.submit(() -> {
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
});
BlockWarsAPI.getGameData().setRegion(newRegion);
}
public static void beforeExpand() {
Point minPoint = BlockWarsAPI.getGameData().getRegion().getMin();
Point maxPoint = BlockWarsAPI.getGameData().getRegion().getMax();
Point newMaxPoint = new Point(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ());
Region newRegion = new Region(BlockWarsAPI.getGameData().getRegion().getWorld(), minPoint, newMaxPoint);
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld());
com.yaohun.bwaddon.Main.executorService.submit(() -> {
BlockVector3 vector1 = BlockVector3.at(maxPoint.getX() + 2, minPoint.getY() - 1, minPoint.getZ() - 1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX() + 2, maxPoint.getY(), maxPoint.getZ() + 1);
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
BlockVector3 vector3 = BlockVector3.at(maxPoint.getX() + 1, minPoint.getY(), minPoint.getZ());
BlockVector3 vector4 = BlockVector3.at(maxPoint.getX() + 2, maxPoint.getY(), maxPoint.getZ());
CuboidRegion cuboidRegion1 = new CuboidRegion(weWorld, vector3, vector4);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion1, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
});
BlockWarsAPI.getGameData().setRegion(newRegion);
}
/*
* 向右拆除
* */
public static void beforeDisassemble() {
Point minPoint = BlockWarsAPI.getGameData().getRegion().getMin();
Point maxPoint = BlockWarsAPI.getGameData().getRegion().getMax();
if (maxPoint.getX() <= 103){
Bukkit.broadcastMessage("§c[消息]§a已经是最小了!");
return;
}
Point newMaxPoint = new Point(maxPoint.getX() - 1, maxPoint.getY(), maxPoint.getZ());
Region newRegion = new Region(BlockWarsAPI.getGameData().getRegion().getWorld(), minPoint, newMaxPoint);
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld());
BlockVector3 vector1 = BlockVector3.at(maxPoint.getX() + 1, minPoint.getY() - 1, minPoint.getZ() - 1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 1);
com.yaohun.bwaddon.Main.executorService.submit(() -> {
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameData().getRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
});
BlockWarsAPI.getGameData().setRegion(newRegion);
}
public static void circleExpand() { // 扩建一圈
Region region = BlockWarsAPI.getGameData().getRegion(); // 获取当前区域大小
Point minPoint = region.getMin();
Point maxPoint = region.getMax();
Point newMaxPoint = new Point(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 1);
Region newRegion = new Region(region.getWorld(), minPoint, newMaxPoint);
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(region.getWorld());
BlockVector3 vector1 = BlockVector3.at(maxPoint.getX() + 1, minPoint.getY(), minPoint.getZ());
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 1);
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, vector1, vector2);
BlockVector3 vector3 = BlockVector3.at(maxPoint.getX(), minPoint.getY(), maxPoint.getZ() + 1);
BlockVector3 vector4 = BlockVector3.at(minPoint.getX(), maxPoint.getY(), maxPoint.getZ() + 1);
CuboidRegion cuboidRegion1 = new CuboidRegion(weWorld, vector3, vector4);
BlockVector3 vector5 = BlockVector3.at(maxPoint.getX() + 2, minPoint.getY() - 1, minPoint.getZ() - 1);
BlockVector3 vector6 = BlockVector3.at(maxPoint.getX() + 2, maxPoint.getY(), maxPoint.getZ() + 2);
CuboidRegion cuboidRegion2 = new CuboidRegion(weWorld, vector5, vector6);
BlockVector3 vector9 = BlockVector3.at(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 2);
BlockVector3 vector10 = BlockVector3.at(minPoint.getX() - 1, minPoint.getY() - 1, maxPoint.getZ() + 2);
com.yaohun.bwaddon.Main.executorService.submit(() -> {
CuboidRegion cuboidRegion3 = new CuboidRegion(weWorld, vector9, vector10);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception ignored) {
}
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion1, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception ignored) {
}
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion2, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS));
Operations.complete(editSession.commit());
} catch (Exception ignored) {
}
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion3, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS));
Operations.complete(editSession.commit());
} catch (Exception ignored) {
}
});
BlockWarsAPI.getGameData().setRegion(newRegion);
}
public static void circleDisassemble() { // 缩小一圈
Region region = BlockWarsAPI.getGameData().getRegion(); // 获取当前区域大小
Point minPoint = region.getMin();
Point maxPoint = region.getMax();
if(maxPoint.getX() <= 133){return;}
Point newMaxPoint = new Point(maxPoint.getX() - 1, maxPoint.getY(), maxPoint.getZ() - 1);
Region newRegion = new Region(region.getWorld(), minPoint, newMaxPoint);
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(region.getWorld());
BlockVector3 vector1 = BlockVector3.at(maxPoint.getX() + 1, minPoint.getY() - 1, minPoint.getZ() - 1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX() + 1, maxPoint.getY(), maxPoint.getZ() + 1);
CuboidRegion cuboidRegion0 = new CuboidRegion(weWorld, vector1, vector2);
BlockVector3 vector3 = BlockVector3.at(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ() + 1);
BlockVector3 vector4 = BlockVector3.at(minPoint.getX() - 1, minPoint.getY() - 1, maxPoint.getZ() + 1);
CuboidRegion cuboidRegion1 = new CuboidRegion(weWorld, vector3, vector4);
BlockVector3 vector5 = BlockVector3.at(maxPoint.getX(), minPoint.getY(), minPoint.getZ());
BlockVector3 vector6 = BlockVector3.at(maxPoint.getX(), maxPoint.getY(), maxPoint.getZ());
CuboidRegion cuboidRegion2 = new CuboidRegion(weWorld, vector5, vector6);
BlockVector3 vector7 = BlockVector3.at(maxPoint.getX() - 1, minPoint.getY(), maxPoint.getZ());
BlockVector3 vector8 = BlockVector3.at(minPoint.getX(), maxPoint.getY(), maxPoint.getZ());
com.yaohun.bwaddon.Main.executorService.submit(() -> {
CuboidRegion cuboidRegion3 = new CuboidRegion(weWorld, vector7, vector8);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion0, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion1, BukkitAdapter.asBlockType(Material.AIR));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion2, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion3, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS));
Operations.complete(editSession.commit());
} catch (Exception e) {
}
});
BlockWarsAPI.getGameData().setRegion(newRegion);
}
public static void upExpand(){
Region region = BlockWarsAPI.getGameData().getRegion(); // 获取当前区域大小
Point minPoint = region.getMin(); // 获取当前区域的point_A
Point maxPoint = region.getMax(); // 获取当前区域的point_B
if(maxPoint.getY() >= 2000){
Bukkit.broadcastMessage("§c[消息]§a已经最大了,不能再提升高度啦!");
return;
}
BlockVector3 vector1 = BlockVector3.at(minPoint.getX()-1, maxPoint.getY()+1, minPoint.getZ()-1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX()+1, maxPoint.getY(), maxPoint.getZ()+1);
com.yaohun.bwaddon.Main.executorService.submit(() -> {
CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.makeCuboidWalls(cuboidRegion, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS)); // 设置当前框的为AIR
} catch (Exception e) {
e.printStackTrace();
}
});
region.setMax(new Point(maxPoint.getX(), maxPoint.getY()+1, maxPoint.getZ()));
BlockWarsAPI.getGameData().setRegion(region);
}
public static void upDisassemble(){
Region region = BlockWarsAPI.getGameData().getRegion(); // 获取当前区域大小
Point minPoint = region.getMin(); // 获取当前区域的point_A
Point maxPoint = region.getMax(); // 获取当前区域的point_B
if(maxPoint.getY() <= 10){
Bukkit.broadcastMessage("§c[消息]§a已经最小了,不能再减少层数啦!");
return;
}
BlockVector3 vector1 = BlockVector3.at(minPoint.getX()-1, maxPoint.getY(), minPoint.getZ()-1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX()+1, maxPoint.getY()+2, maxPoint.getZ()+1);
com.yaohun.bwaddon.Main.executorService.submit(() -> {
CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.AIR)); // 设置当前框的为AIR
} catch (Exception e) {
e.printStackTrace();
}
});
region.setMax(new Point(maxPoint.getX(), maxPoint.getY()-1, maxPoint.getZ()));
BlockWarsAPI.getGameData().setRegion(region);
}
/*
* 设置矿区的围墙
* */
public static void setMinerWalls(){
com.yaohun.bwaddon.Main.executorService.submit(() -> {
long startTime = System.currentTimeMillis(); // 记录开始时间
Point minPoint = BlockWarsAPI.getGameRegion().getMin(); // 获取当前区域的point_A
Point maxPoint = BlockWarsAPI.getGameRegion().getMax(); // 获取当前区域的point_B
BlockVector3 vector1 = BlockVector3.at(minPoint.getX()-1, minPoint.getY(), minPoint.getZ()-1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX()+1, maxPoint.getY(), maxPoint.getZ()+1);
CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(BlockWarsAPI.getGameRegion().getWorld()),vector1,vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameRegion().getWorld()))) {
editSession.makeCuboidWalls((com.sk89q.worldedit.regions.Region)cuboidRegion, BukkitAdapter.asBlockType(Material.WHITE_STAINED_GLASS)); // 设置当前框的为AIR
} catch (Exception e) {
e.printStackTrace();
}
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startTime; // 计算耗时
});
}
/*
* 重置矿区大小
* */
public static void resetMinerSize() {
com.yaohun.bwaddon.Main.executorService.submit(() -> {
Point minPoint = BlockWarsAPI.getGameRegion().getMin(); // 获取当前区域的point_A
Point maxPoint = BlockWarsAPI.getGameRegion().getMax(); // 获取当前区域的point_B
BlockVector3 vector1 = BlockVector3.at(minPoint.getX()-1, minPoint.getY()-1, minPoint.getZ()-1);
BlockVector3 vector2 = BlockVector3.at(maxPoint.getX()+1, maxPoint.getY()+1, maxPoint.getZ()+1);
CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(BlockWarsAPI.getGameRegion().getWorld()),vector1,vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(BlockWarsAPI.getGameRegion().getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region)cuboidRegion, BukkitAdapter.asBlockType(Material.AIR)); // 设置当前框的为AIR
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

View File

@ -1,6 +1,10 @@
name: BlockWars
main: me.Demon.BlockWars.Main
version: 1.0.0
version: 1.2.0
api-version: 1.18
depend:
- McLiveAPI
commands:
livegift:
game:
bw: