测试版
This commit is contained in:
parent
c1b5c1bfd6
commit
23d054922b
BIN
lib/paper-1.18.2NMS.jar
Normal file
BIN
lib/paper-1.18.2NMS.jar
Normal file
Binary file not shown.
|
@ -1,6 +1,8 @@
|
|||
package com.yaohun.wheatwar;
|
||||
|
||||
import com.yaohun.wheatwar.effect.SummonTheCow;
|
||||
import com.yaohun.wheatwar.effect.SummonTheVillager;
|
||||
import com.yaohun.wheatwar.effect.SummonTheZombie;
|
||||
import com.yaohun.wheatwar.game.Game;
|
||||
import com.yaohun.wheatwar.listener.GameEffectListener;
|
||||
import com.yaohun.wheatwar.listener.GameListener;
|
||||
|
@ -10,6 +12,7 @@ import org.bukkit.command.Command;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import tools.GameUtil;
|
||||
|
||||
public class WheatWar extends JavaPlugin {
|
||||
|
@ -43,7 +46,15 @@ public class WheatWar extends JavaPlugin {
|
|||
return true;
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("test1")){
|
||||
SummonTheVillager.apply(getGame(),(Player) sender,"1111",1);
|
||||
SummonTheVillager.apply(getGame(), (Player) sender, "村民", 50);
|
||||
sender.sendMessage("执行成功.");
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("test2")){
|
||||
SummonTheCow.apply(getGame(), (Player) sender, "路人", 50);
|
||||
sender.sendMessage("执行成功.");
|
||||
}
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("test3")){
|
||||
SummonTheZombie.apply(getGame(), (Player) sender, "僵尸先生", 10);
|
||||
sender.sendMessage("执行成功.");
|
||||
}
|
||||
}
|
||||
|
|
154
src/main/java/com/yaohun/wheatwar/effect/SummonTheCow.java
Normal file
154
src/main/java/com/yaohun/wheatwar/effect/SummonTheCow.java
Normal file
|
@ -0,0 +1,154 @@
|
|||
package com.yaohun.wheatwar.effect;
|
||||
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.game.Game;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import org.bukkit.Bukkit;
|
||||
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.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
import tools.CDTimeAPI;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SummonTheCow {
|
||||
|
||||
public static void apply(Game game, Player zhubo, String userName, int amount) {
|
||||
if (!game.isStarted()) {
|
||||
return;
|
||||
}
|
||||
// 获取主播的uuid
|
||||
UUID uuid = zhubo.getUniqueId();
|
||||
// 计时器key
|
||||
String timepieceKey = "SummonCowEffect";
|
||||
startTimepieceEvent(game,zhubo,userName,timepieceKey);
|
||||
if(CDTimeAPI.isCD(uuid,timepieceKey)){
|
||||
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (95L * amount);
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
|
||||
} else {
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,95L * 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(WheatWar.inst(), 0L, 2L);
|
||||
game.addTasks(task);
|
||||
}
|
||||
|
||||
public static HashMap<UUID, Location> locationMap = new HashMap<>(); // 村民 正在执行的任务 需前往的地方
|
||||
|
||||
public static void spawnMobs(Game game,String userName) {
|
||||
Location location = game.getFarmlandRandom().clone().add(0,1,0);
|
||||
Cow entity = (Cow) location.getWorld().spawnEntity(location, EntityType.COW);
|
||||
entity.setCollidable(false);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setCustomName("§c" + userName);
|
||||
Location centralPoint = game.getCentralPoint();
|
||||
// 计算方向
|
||||
Vector direction = centralPoint.toVector().subtract(location.toVector()).normalize();
|
||||
// 设置初速度
|
||||
double initialVerticalVelocity = 0.4; // 向上抛的速度
|
||||
double horizontalVelocity = 1.35; // 控制水平抛出的力度
|
||||
// 创建一个向量,包括水平和垂直方向的速度
|
||||
Vector velocity = direction.multiply(horizontalVelocity).setY(initialVerticalVelocity);
|
||||
entity.setVelocity(velocity);
|
||||
new BukkitRunnable() {
|
||||
private int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if(i >= 15){
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
game.getWorld().spawnParticle(Particle.ELECTRIC_SPARK,entity.getLocation().clone().add(0,1,0),2);
|
||||
//game.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,entity.getLocation().clone().add(0,1,0),2);
|
||||
i++;
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(),0,1L);
|
||||
new BukkitRunnable() {
|
||||
private int amount = 10;
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = entity.getUniqueId();
|
||||
// 若村民死亡则计时器种植并结束村民任务
|
||||
if (entity.isDead()) {
|
||||
locationMap.remove(uuid);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if(amount <= 0){
|
||||
entity.damage(999.0D);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
// 检测村民是否存在任务 若存在则抵达目标方块时触发消息 ”已完成任务“
|
||||
//
|
||||
// 若村民没有任务则获取坐标后通过NMS设置村民寻路目标坐标 并put添加任务
|
||||
if (locationMap.containsKey(uuid)) {
|
||||
Location location1 = locationMap.get(uuid);
|
||||
if (entity.getLocation().distance(location1) <= 1.0) {
|
||||
amount--;
|
||||
//到达目标小麦位置
|
||||
locationMap.remove(uuid);
|
||||
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
|
||||
Block block = location.getWorld().getBlockAt(location1);
|
||||
if(!block.getType().equals(Material.AIR)) {
|
||||
if (block.getType().equals(Material.WHEAT)) {
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
if (ageable.getAge() == 7) {
|
||||
ageable.setAge(3);
|
||||
block.setBlockData(ageable);
|
||||
} else {
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 1, 0.5), 5, 0.5, 0.5, 0.5, 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Vector direction = location1.toVector().subtract(entity.getLocation().toVector()).normalize();
|
||||
Vector velocity = direction.multiply(0.25);
|
||||
entity.setVelocity(velocity);
|
||||
}
|
||||
} else {
|
||||
// 优先寻找未种小麦的地 已种小麦未成熟的地 坐标
|
||||
Location location1 = game.getPriorityClearLocation();
|
||||
if(location1 == null){
|
||||
Bukkit.broadcastMessage("!游戏结束!路人获胜!");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
|
||||
nmsEntity.D().a(location1.getX(), location1.getY(), location1.getZ(), 1.0F);
|
||||
locationMap.put(uuid, location1);
|
||||
entity.setCustomName("§c" + userName+" [§6"+amount+"§c]");
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(), 20L, 1L);
|
||||
}
|
||||
}
|
|
@ -2,9 +2,12 @@ package com.yaohun.wheatwar.effect;
|
|||
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.game.Game;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
@ -13,6 +16,8 @@ import org.bukkit.scheduler.BukkitTask;
|
|||
import org.bukkit.util.Vector;
|
||||
import tools.CDTimeAPI;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SummonTheVillager {
|
||||
|
@ -27,10 +32,10 @@ public class SummonTheVillager {
|
|||
String timepieceKey = "SummonVillagerEffect";
|
||||
startTimepieceEvent(game,zhubo,userName,timepieceKey);
|
||||
if(CDTimeAPI.isCD(uuid,timepieceKey)){
|
||||
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (245L * amount);
|
||||
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (95L * amount);
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
|
||||
} else {
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,245L * amount);
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,95L * amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,15 +52,20 @@ public class SummonTheVillager {
|
|||
}
|
||||
spawnMobs(game,userName);
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(), 0L, 5L);
|
||||
}.runTaskTimer(WheatWar.inst(), 0L, 2L);
|
||||
game.addTasks(task);
|
||||
}
|
||||
|
||||
public static HashMap<UUID, Location> locationMap = new HashMap<>(); // 村民 正在执行的任务 需前往的地方
|
||||
|
||||
public static void spawnMobs(Game game,String userName) {
|
||||
Location location = game.getFarmlandRandom().clone().add(0,1,0);
|
||||
Villager entity = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
|
||||
entity.setProfession(Villager.Profession.FARMER);
|
||||
entity.setCollidable(false);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setCustomName("§a" + userName);
|
||||
entity.setCustomName("§b" + userName);
|
||||
entity.setHealth(2);
|
||||
Location centralPoint = game.getCentralPoint();
|
||||
// 计算方向
|
||||
Vector direction = centralPoint.toVector().subtract(location.toVector()).normalize();
|
||||
|
@ -74,9 +84,71 @@ public class SummonTheVillager {
|
|||
return;
|
||||
}
|
||||
game.getWorld().spawnParticle(Particle.ELECTRIC_SPARK,entity.getLocation().clone().add(0,1,0),2);
|
||||
//game.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,entity.getLocation().clone().add(0,1,0),2);
|
||||
i++;
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(),0,1L);
|
||||
new BukkitRunnable() {
|
||||
private int amount = 10;
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = entity.getUniqueId();
|
||||
// 若村民死亡则计时器种植并结束村民任务
|
||||
if (entity.isDead()) {
|
||||
locationMap.remove(uuid);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if(amount <= 0){
|
||||
entity.damage(999.0D);
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
// 检测村民是否存在任务 若存在则抵达目标方块时触发消息 ”已完成任务“
|
||||
//
|
||||
// 若村民没有任务则获取坐标后通过NMS设置村民寻路目标坐标 并put添加任务
|
||||
if (locationMap.containsKey(uuid)) {
|
||||
Location location1 = locationMap.get(uuid);
|
||||
if (entity.getLocation().distance(location1) <= 1.0) {
|
||||
amount--;
|
||||
//到达目标小麦位置
|
||||
locationMap.remove(uuid);
|
||||
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
|
||||
Block block = location.getWorld().getBlockAt(location1);
|
||||
if(block.getType().equals(Material.AIR)){
|
||||
block.setType(Material.WHEAT);
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
ageable.setAge(3);
|
||||
block.setBlockData(ageable);
|
||||
}
|
||||
block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5, 1, 0.5), 5, 0.5, 0.5, 0.5, 0.1);
|
||||
}else if(block.getType().equals(Material.WHEAT)){
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
ageable.setAge(7);
|
||||
block.setBlockData(ageable);
|
||||
}
|
||||
block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, block.getLocation().add(0.5, 1, 0.5), 5, 0.5, 0.5, 0.5, 0.1);
|
||||
}
|
||||
} else {
|
||||
Vector direction = location1.toVector().subtract(entity.getLocation().toVector()).normalize();
|
||||
Vector velocity = direction.multiply(0.25);
|
||||
entity.setVelocity(velocity);
|
||||
}
|
||||
} else {
|
||||
// 优先寻找未种小麦的地 已种小麦未成熟的地 坐标
|
||||
Location location1 = game.getPriorityRepairLocation();
|
||||
if(location1 == null){
|
||||
Bukkit.broadcastMessage("!游戏结束!村民获胜!");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
net.minecraft.world.entity.EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
|
||||
nmsEntity.D().a(location1.getX(), location1.getY(), location1.getZ(), 1.0F);
|
||||
locationMap.put(uuid, location1);
|
||||
entity.setCustomName("§b" + userName+"[§6"+amount+"§b]");
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(), 20L, 1L);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
package com.yaohun.wheatwar.effect;
|
||||
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.game.Game;
|
||||
import net.minecraft.world.entity.EntityInsentient;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.*;
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SummonTheZombie {
|
||||
|
||||
public static void apply(Game game, Player zhubo, String userName, int amount) {
|
||||
if (!game.isStarted()) {
|
||||
return;
|
||||
}
|
||||
// 获取主播的uuid
|
||||
UUID uuid = zhubo.getUniqueId();
|
||||
// 计时器key
|
||||
String timepieceKey = "SummonZombieEffect";
|
||||
startTimepieceEvent(game,zhubo,userName,timepieceKey);
|
||||
if(CDTimeAPI.isCD(uuid,timepieceKey)){
|
||||
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (95L * amount);
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
|
||||
} else {
|
||||
CDTimeAPI.setPlayerCD(uuid,timepieceKey,95L * 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(WheatWar.inst(), 0L, 2L);
|
||||
game.addTasks(task);
|
||||
}
|
||||
|
||||
public static HashMap<UUID, Integer> zombieKillMap = new HashMap<>(); // 村民 正在执行的任务 需前往的地方
|
||||
|
||||
public static void spawnMobs(Game game,String userName) {
|
||||
Location location = game.getFarmlandRandom().clone().add(0,1,0);
|
||||
Zombie entity = (Zombie) location.getWorld().spawnEntity(location, EntityType.ZOMBIE);
|
||||
entity.setCollidable(false);
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setCustomName("§9" + userName+"[§e"+3+"§9]");
|
||||
zombieKillMap.put(entity.getUniqueId(),3);
|
||||
entity.setBaby(false);
|
||||
entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.4);
|
||||
entity.getAttribute(Attribute.GENERIC_FOLLOW_RANGE).setBaseValue(50);
|
||||
Location centralPoint = game.getCentralPoint();
|
||||
// 计算方向
|
||||
Vector direction = centralPoint.toVector().subtract(location.toVector()).normalize();
|
||||
// 设置初速度
|
||||
double initialVerticalVelocity = 0.4; // 向上抛的速度
|
||||
double horizontalVelocity = 1.35; // 控制水平抛出的力度
|
||||
// 创建一个向量,包括水平和垂直方向的速度
|
||||
Vector velocity = direction.multiply(horizontalVelocity).setY(initialVerticalVelocity);
|
||||
entity.setVelocity(velocity);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(entity.isDead()){
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
entity.setCustomName("§9" + userName+"[§e"+zombieKillMap.get(entity.getUniqueId())+"§9]");
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(), 20L,10L);
|
||||
}
|
||||
}
|
|
@ -77,6 +77,106 @@ public class Game {
|
|||
Random random = new Random();
|
||||
return locationList.get(random.nextInt(locationList.size()));
|
||||
}
|
||||
// 获取一个未种植小麦的坐标
|
||||
public Location getAirWheatLocation(){
|
||||
Location location = null;
|
||||
List<Location> locationList = getWheatList();
|
||||
Collections.shuffle(locationList);
|
||||
for (Location loc : locationList){
|
||||
Block block = world.getBlockAt(loc);
|
||||
if (block.getType().equals(Material.AIR)) {
|
||||
location = loc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
// 获取未成熟小麦的坐标
|
||||
public Location getAgeableWheatLocation(){
|
||||
Location location = null;
|
||||
List<Location> locationList = getWheatList();
|
||||
Collections.shuffle(locationList);
|
||||
for (Location loc : locationList){
|
||||
Block block = world.getBlockAt(loc);
|
||||
if (!block.getType().equals(Material.AIR) && block.getType().equals(Material.WHEAT)) {
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
if (ageable.getAge() < 7) {
|
||||
location = loc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
// 获取已成熟小麦的坐标
|
||||
public Location getMatureWheatLocation(){
|
||||
Location location = null;
|
||||
List<Location> locationList = getWheatList();
|
||||
Collections.shuffle(locationList);
|
||||
for (Location loc : locationList){
|
||||
Block block = world.getBlockAt(loc);
|
||||
if (!block.getType().equals(Material.AIR) && block.getType().equals(Material.WHEAT)) {
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
if (ageable.getAge() == 7) {
|
||||
location = loc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
// 优先寻找未种小麦的地 已种小麦未成熟的地
|
||||
public Location getPriorityRepairLocation(){
|
||||
Location location = null;
|
||||
List<Location> locationList = getWheatList();
|
||||
Collections.shuffle(locationList);
|
||||
for (Location loc : locationList){
|
||||
Block block = world.getBlockAt(loc);
|
||||
if(!block.getType().equals(Material.AIR) && block.getType().equals(Material.WHEAT)){
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
if (ageable.getAge() < 7) {
|
||||
location = loc.clone().add(0.5,0,0.5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else if (block.getType().equals(Material.AIR)) {
|
||||
location = loc.clone().add(0.5,0,0.5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
// 优先寻找未种小麦的地 已种小麦未成熟的地
|
||||
public Location getPriorityClearLocation(){
|
||||
Location location = null;
|
||||
List<Location> locationList = getWheatList();
|
||||
Collections.shuffle(locationList);
|
||||
for (Location loc : locationList){
|
||||
Block block = world.getBlockAt(loc);
|
||||
if(block.getType().equals(Material.WHEAT)){
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
if(ageable.getAge() >= 7){
|
||||
location = loc.clone().add(0.5,0,0.5);
|
||||
break;
|
||||
}else if (ageable.getAge() < 5) {
|
||||
location = loc.clone().add(0.5,0,0.5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public World getWorld() {return world;}
|
||||
public List<Location> getWheatList() {return wheatList;}
|
||||
public Region getRegion() {return region;}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class GameSite {
|
|||
int i = 0;
|
||||
for (Location location : locationList){
|
||||
Block block = world.getBlockAt(location);
|
||||
if (!block.getType().equals(Material.AIR)) {
|
||||
if (!block.getType().equals(Material.AIR) && block.getType().equals(Material.WHEAT)) {
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Ageable ageable) {
|
||||
if (ageable.getAge() == 7) {
|
||||
|
@ -33,4 +33,6 @@ public class GameSite {
|
|||
return i;
|
||||
}
|
||||
|
||||
// 获取哪个坐标没有种小麦
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,61 @@
|
|||
package com.yaohun.wheatwar.listener;
|
||||
|
||||
import com.yaohun.wheatwar.effect.SummonTheZombie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GameListener implements Listener {
|
||||
|
||||
public static HashMap<UUID,UUID> zombieTargetMap = new HashMap<>();
|
||||
@EventHandler
|
||||
public void onZombieTarget(EntityTargetEvent event) {
|
||||
// 检查是否是僵尸
|
||||
if (event.getEntityType() == EntityType.ZOMBIE) {
|
||||
// 检查目标是否是玩家
|
||||
if (event.getTarget() instanceof Player) {
|
||||
// 取消该事件以阻止僵尸将玩家设为仇恨目标
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if(event.getTarget() instanceof Villager villager){
|
||||
UUID vuuid = villager.getUniqueId();
|
||||
UUID uuid = event.getEntity().getUniqueId();
|
||||
/*// 若这个村民已经被僵尸锁定则无法被选中
|
||||
if(zombieTargetMap.containsKey(vuuid)){
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
zombieTargetMap.put(vuuid,uuid);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ondeath(EntityDeathEvent e){
|
||||
// 检查被杀的实体是否是村民
|
||||
if (e.getEntity() instanceof Villager villager) {
|
||||
// 检查村民是否是被僵尸杀死的
|
||||
if (villager.getLastDamageCause() instanceof EntityDamageByEntityEvent damageEvent) {
|
||||
if (damageEvent.getDamager() instanceof Zombie zombie) {
|
||||
HashMap<UUID, Integer> zombieKillMap = SummonTheZombie.zombieKillMap;
|
||||
if(zombieKillMap.get(zombie.getUniqueId()) != null){
|
||||
int newAmount = zombieKillMap.get(zombie.getUniqueId()) - 1;
|
||||
if(newAmount >= 1){
|
||||
SummonTheZombie.zombieKillMap.put(zombie.getUniqueId(),newAmount);
|
||||
} else {
|
||||
zombie.damage(999.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
5
src/main/java/com/yaohun/wheatwar/util/NMSVillager.java
Normal file
5
src/main/java/com/yaohun/wheatwar/util/NMSVillager.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package com.yaohun.wheatwar.util;
|
||||
|
||||
public class NMSVillager {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user