129 lines
5.1 KiB
Java
129 lines
5.1 KiB
Java
package com.yaohun.farmingwar.effects;
|
|
|
|
import com.yaohun.farmingwar.FarmingWar;
|
|
import com.yaohun.farmingwar.game.Game;
|
|
import com.yaohun.farmingwar.game.GameSite;
|
|
import com.yaohun.farmingwar.game.Region;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Particle;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.data.Ageable;
|
|
import org.bukkit.entity.Cow;
|
|
import org.bukkit.entity.EntityType;
|
|
import org.bukkit.entity.Panda;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
import org.bukkit.util.Vector;
|
|
import tools.CDTimeAPI;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
public class SummonThePanda {
|
|
|
|
public static void apply(Game game, Player zhubo, String userName, int amount) {
|
|
if (!game.isStarted()) {
|
|
return;
|
|
}
|
|
// 获取主播的uuid
|
|
UUID uuid = zhubo.getUniqueId();
|
|
// 计时器key
|
|
String timepieceKey = "SummonPandaEffect";
|
|
startTimepieceEvent(game,zhubo,userName,timepieceKey);
|
|
if(CDTimeAPI.isCD(uuid,timepieceKey)){
|
|
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount);
|
|
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
|
|
} else {
|
|
CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount);
|
|
}
|
|
}
|
|
|
|
public static void startTimepieceEvent(Game game,Player zhubo,String userName,String timepieceKey) {
|
|
if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) {
|
|
return;
|
|
}
|
|
BukkitTask task = new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) {
|
|
cancel();
|
|
return;
|
|
}
|
|
spawnMobs(game,userName);
|
|
}
|
|
}.runTaskTimer(FarmingWar.inst(), 0L, 5L);
|
|
game.addTasks(task);
|
|
}
|
|
|
|
public static void spawnMobs(Game game,String userName){
|
|
Region region = game.getRegion();
|
|
Location location = GameSite.getMinerWheat_MaxAmount_Location();
|
|
location.setYaw(-90);
|
|
EntityType entityType = EntityType.PANDA;
|
|
Panda entity = (Panda) location.getWorld().spawnEntity(location, entityType);
|
|
entity.setMaxHealth(100);
|
|
entity.setCustomNameVisible(true);
|
|
entity.setCustomName("§c" + userName);
|
|
BukkitTask task = new BukkitRunnable() {
|
|
private int i = 0;
|
|
// 计算将在多少i后自动消失
|
|
private double remove_x_i = (region.getMax().getX() - region.getMin().getX()) * 4;
|
|
private List<Integer> integerList = new ArrayList<>();
|
|
@Override
|
|
public void run() {
|
|
Location location = entity.getLocation().clone();
|
|
if(i >= remove_x_i){
|
|
if(!entity.isDead()) {
|
|
entity.remove();
|
|
}
|
|
cancel();
|
|
return;
|
|
}
|
|
if (entity.isDead() || location.getX() >= region.getMax().getX()+0.5) {
|
|
entity.remove();
|
|
cancel();
|
|
return;
|
|
}
|
|
Vector vector0 = new Vector(1, 0, 0);
|
|
vector0.normalize();
|
|
vector0.multiply(FarmingWar.getGameManager().getMovespeeds());
|
|
entity.setTarget(null);
|
|
entity.setRotation(-90, 0);
|
|
entity.setVelocity(vector0);
|
|
location.setY(region.getMax().getY());
|
|
// 破坏方块的范围
|
|
int range = 1;
|
|
int centerZ = location.getBlockZ();
|
|
// 遍历周围的 z 坐标
|
|
for (int z = centerZ - range; z <= centerZ + range; z++) {
|
|
// 获取当前坐标的方块
|
|
Block block = region.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), z);
|
|
// 判断这个方块是否在游戏场地
|
|
if (region.isInRegion(block.getLocation())) {
|
|
// 获取这个方块的ID代号
|
|
int hashCode = block.hashCode();
|
|
// 判断这个方块是否已录入系统 若已录入则跳过
|
|
if (!integerList.contains(hashCode)) {
|
|
integerList.add(hashCode);
|
|
// 判断方块是否是小麦
|
|
if (block.getType() == Material.WHEAT) {
|
|
block.setType(Material.AIR);
|
|
// Main.configYml.addUser_Wheat(userName, 1);
|
|
block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1);
|
|
} else {
|
|
block.getRelative(0, -1, 0).setType(Material.FARMLAND);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
i++;
|
|
}
|
|
}.runTaskTimer(FarmingWar.inst(), 1L, 1L);
|
|
game.addTasks(task);
|
|
}
|
|
|
|
}
|