测试版

This commit is contained in:
yaohunya 2024-11-01 14:19:42 +08:00
parent 23d054922b
commit 88f8dd6fcb
21 changed files with 1553 additions and 74 deletions

View File

@ -1,29 +1,47 @@
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.data.RepairGiftGui;
import com.yaohun.wheatwar.effect.*;
import com.yaohun.wheatwar.game.Game;
import com.yaohun.wheatwar.listener.GameEffectListener;
import com.yaohun.wheatwar.listener.GameListener;
import com.yaohun.wheatwar.listener.GamePotect;
import com.yaohun.wheatwar.listener.JoinListener;
import com.yaohun.wheatwar.liveevent.GiftEventHandler;
import com.yaohun.wheatwar.liveevent.GiftListener;
import com.yaohun.wheatwar.liveevent.LikeListener;
import com.yaohun.wheatwar.manage.GameManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import tools.GameUtil;
import tools.RandomUtil;
import java.util.ArrayList;
import java.util.List;
public class WheatWar extends JavaPlugin {
private static WheatWar instance;
private static Game game;
private static GameManager gameManager;
@Override
public void onEnable() {
instance = this;
gameManager = new GameManager();
game = new Game();
getServer().getPluginManager().registerEvents(new GiftListener(),this);
getServer().getPluginManager().registerEvents(new LikeListener(gameManager),this);
getServer().getPluginManager().registerEvents(new RepairGiftGui(),this);
getServer().getPluginManager().registerEvents(new GameEffectListener(),this);
getServer().getPluginManager().registerEvents(new GameListener(),this);
getServer().getPluginManager().registerEvents(new GamePotect(),this);
@ -50,18 +68,90 @@ public class WheatWar extends JavaPlugin {
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("test2")){
SummonTheCow.apply(getGame(), (Player) sender, "路人", 50);
SummonTheSheep.apply(getGame(), (Player) sender, "路人", 50);
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("test3")){
SummonTheZombie.apply(getGame(), (Player) sender, "僵尸先生", 10);
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("test4")){
SummonTheBombsTNT.apply(getGame(), (Player) sender, "僵尸先生", 10);
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("test5")){
SummonTheTNTRain.apply(getGame(), (Player) sender, "僵尸先生", 50);
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("test6")){
SummonTheSheepPro.apply(getGame(), (Player) sender, "暴躁小杨", 10);
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("test7")){
Player player = (Player) sender;
Location location = player.getLocation();
Villager entity = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
entity.setAI(false);
entity.setProfession(Villager.Profession.FARMER);
sender.sendMessage("执行成功.");
}
if(args.length == 1 && args[0].equalsIgnoreCase("play")){
Player player = (Player) sender;
Location center = new Location(Bukkit.getWorld("world"), 1, 66, -2);
// 启动计时器
new BukkitRunnable() {
private int ticks = 0; // 计时器的 ticks 变量1秒20 ticks
private final double radius = 30.0; // 绕圈半径
private final int duration = 36000 * 10; // 1分钟1200 ticks
@Override
public void run() {
if(player == null || !player.isOnline()){
cancel();
return;
}
if (ticks >= duration) { // 计时结束
cancel();
return;
}
// 计算当前旋转角度
double angle = Math.toRadians((ticks * 0.3) % 360); // 每tick增加角度控制旋转速度
double x = center.getX() + radius * Math.cos(angle);
double z = center.getZ() + radius * Math.sin(angle);
double y = center.getY() + 13;
// 更新玩家位置和朝向
Location playerLoc = player.getLocation();
playerLoc.setX(x);
playerLoc.setY(y);
playerLoc.setZ(z);
// 设置玩家面朝中心点
playerLoc.setDirection(center.toVector().subtract(playerLoc.toVector()));
player.teleport(playerLoc);
ticks++;
}
}.runTaskTimer(instance, 0L, 1L); // 每tick执行一次
sender.sendMessage("执行成功.");
return true;
}
if (args.length == 2 && args[0].equalsIgnoreCase("effect")) {
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;
}
public static WheatWar inst(){return instance;}
public static Game getGame() {return game;}
public static GameManager getGameManager() {return gameManager;}
}

View File

@ -0,0 +1,65 @@
package com.yaohun.wheatwar.data;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import tools.GameUtil;
public class GiftData {
private String giftName;
private String event;
private String comple_type;
private String sounds;
private int amount = 0;
public GiftData(String giftName, FileConfiguration yml){
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 = yml.getString(str+"声音","NULL");
this.event = yml.getString(str + "效果");
if (comple_type.equalsIgnoreCase("NULL")) {
Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName+" 声音: "+this.sounds);
}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 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")){
// FarmingWar.getGame().effect_takeComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §c-"+new_amount);
} else if(comple_type.equalsIgnoreCase("add")){
// FarmingWar.getGame().effect_addComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §b+"+new_amount);
}
}
public void OutPlaySoundsEvent() {
if(!sounds.equalsIgnoreCase("NULL")) {
GameUtil.sendAllSound(sounds);
}
}
}

View File

@ -0,0 +1,48 @@
package com.yaohun.wheatwar.data;
import tools.GameUtil;
public class LikeData {
private String effectKey;
private int needAmount;
private int nowAmount;
private String sound;
public LikeData(String effectKey, int needAmount, String sound){
this.effectKey = effectKey;
this.needAmount = needAmount;
this.nowAmount = 0;
this.sound = sound;
}
public String getEffectKey() {
return effectKey;
}
public boolean meetTheQuantityRequirement(){
if(nowAmount >= needAmount){
return true;
}
return false;
}
public int getNeedAmount() {
return needAmount;
}
public int getNowAmount() {
return nowAmount;
}
public void addNowAmount(int amount){
setNowAmount(getNowAmount()+amount);
}
public void setNowAmount(int nowAmount) {
this.nowAmount = nowAmount;
}
public void OutPlaySoundsEvent() {
GameUtil.sendAllSound(this.sound);
}
}

View File

@ -0,0 +1,255 @@
package com.yaohun.wheatwar.data;
import com.yaohun.wheatwar.WheatWar;
import com.yaohun.wheatwar.liveevent.GiftEventHandler;
import com.yaohun.wheatwar.util.GiftUtil;
import de.tr7zw.nbtapi.NBTItem;
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 tools.GameUtil;
import tools.RandomUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RepairGiftGui implements Listener {
public static String invTitle = "我的世界整蛊 - 礼物触发管理";
public static String invTitle2 = "请选择触发礼物的数量";
public static void OpenGui(Player p,ItemStack stack){
Inventory inv = Bukkit.createInventory(null,18,invTitle2);
inv.setItem(0,getGiftStack(stack,1,1));
inv.setItem(1,getGiftStack(stack,2,2));
inv.setItem(2,getGiftStack(stack,3,3));
inv.setItem(3,getGiftStack(stack,5,5));
inv.setItem(4,getGiftStack(stack,6,6));
inv.setItem(5,getGiftStack(stack,7,7));
inv.setItem(6,getGiftStack(stack,8,8));
inv.setItem(7,getGiftStack(stack,9,9));
inv.setItem(8,getGiftStack(stack,10,10));
inv.setItem(9,getGiftStack(stack,6,66));
inv.setItem(10,getGiftStack(stack,18,188));
inv.setItem(11,getGiftStack(stack,52,520));
inv.setItem(12,getGiftStack(stack,64,1314));
p.openInventory(inv);
}
public static ItemStack getGiftStack(ItemStack stack,int itemAmount,int amount){
ItemStack item = stack.clone();
item.setAmount(itemAmount);
ItemMeta meta = item.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add(" ");
lore.add("§b§l★ §6点击 §7执行§e"+amount+"§7次");
meta.setLore(lore);
item.setItemMeta(meta);
NBTItem nbti = new NBTItem(item);
nbti.setInteger("giftAmount",amount);
return nbti.getItem();
}
@EventHandler
public void onClick(InventoryClickEvent e){
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
if(e.getView().getTitle().equalsIgnoreCase(invTitle2)){
e.setCancelled(true);
if(rawSlot < 0 || rawSlot >= 18) { return;}
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 = nbti.getInteger("giftAmount");
GiftData giftData = WheatWar.getGameManager().getGiftData(giftName);
giftData.OutCompleEvent(amount);
String hide_userName = GameUtil.hideName(userName);
String eventName = giftData.getEvent();
if (GiftUtil.specialGiftEffectTriggers(zhubo, eventName, hide_userName, amount)) {
giftData.OutPlaySoundsEvent();
return;
}
if (amount <= 1) {
String title = "§c" + eventName;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, userName, eventName);
} else {
String title = "§c" + eventName + " x" + amount;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(WheatWar.inst(), () -> {
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, userName, eventName);
}, (long) i * 5);
}
}
}
}
} else if(e.getView().getTitle().equalsIgnoreCase(invTitle)){
if(rawSlot >= 0) {
e.setCancelled(true);
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;
zhubo.closeInventory();
if(WheatWar.getGameManager().getGiftData(giftName) == null){
zhubo.sendTitle("§r", "§c未设置效果",10, 30, 10);
return;
}
if(e.getClick() == ClickType.SHIFT_RIGHT || e.getClick() == ClickType.SHIFT_LEFT){
OpenGui(zhubo,stack);
return;
}
if (e.getClick() == ClickType.RIGHT) {
amount = 10;
}
GiftData giftData = WheatWar.getGameManager().getGiftData(giftName);
giftData.OutCompleEvent(amount);
String hide_userName = GameUtil.hideName(userName);
String eventName = giftData.getEvent();
if(GiftUtil.specialGiftEffectTriggers(zhubo,eventName,hide_userName,amount)){
giftData.OutPlaySoundsEvent();
return;
}
if (amount <= 1) {
String title = "§c" + eventName;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
giftData.OutPlaySoundsEvent();
GiftEventHandler.SendHandLer(zhubo, userName, eventName);
} else {
String title = "§c" + eventName + " x" + amount;
String subtitle = "§9" + hide_userName;
zhubo.sendTitle(title, subtitle, 0, 30, 10);
for (int i = 0; i < amount; i++) {
Bukkit.getScheduler().runTaskLater(WheatWar.inst(), () -> {
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 = WheatWar.getGameManager().getGiftDataMap();
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 (WheatWar.getGameManager().getGiftData(name) != null) {
GiftData giftData = WheatWar.getGameManager().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自定义数量");
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

@ -0,0 +1,73 @@
package com.yaohun.wheatwar.effect;
import com.yaohun.wheatwar.WheatWar;
import com.yaohun.wheatwar.game.Game;
import com.yaohun.wheatwar.listener.GameListener;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.attribute.Attribute;
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.HashMap;
import java.util.UUID;
public class SummonTheBombsTNT {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {
return;
}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "SummonBombsTNTEffect";
startTimepieceEvent(game,zhubo,userName,timepieceKey);
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (195L * amount);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,195L * 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;
}
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_CHICKEN_EGG,1,1);
spawnMobs(game);
}
}.runTaskTimer(WheatWar.inst(), 0L, 4L);
game.addTasks(task);
}
public static void spawnMobs(Game game) {
for (Entity entity : game.getWorld().getEntities()){
if (entity instanceof ZombieVillager || entity instanceof Zombie) {
if(entity.getPassengers().size() <= 0) {
// 在僵尸头上生成TNT
TNTPrimed tnt = (TNTPrimed) entity.getWorld().spawn(entity.getLocation().add(0, 2, 0), TNTPrimed.class);
GameListener.whiteListTNT.add(tnt.getUniqueId());
// 设置爆炸范围和伤害监听器
tnt.setYield(2.0F); // 爆炸范围默认值为 4.0F
tnt.setIsIncendiary(false); // 如果需要爆炸引起火焰可设置为 true
tnt.setFuseTicks(40); // 设置2秒后爆炸1秒=20 ticks
// 将TNT附加在僵尸头上
entity.addPassenger(tnt);
break;
}
}
}
}
}

View File

@ -2,28 +2,24 @@ 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.*;
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.entity.Sheep;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import tools.CDTimeAPI;
import tools.RandomUtil;
import java.util.HashMap;
import java.util.UUID;
public class SummonTheCow {
public class SummonTheSheep {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {
@ -63,7 +59,9 @@ public class SummonTheCow {
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);
Sheep entity = (Sheep) location.getWorld().spawnEntity(location, EntityType.SHEEP);
DyeColor dyeColor = DyeColor.values()[RandomUtil.getRandomInt(0, 6)];
entity.setColor(dyeColor);
entity.setCollidable(false);
entity.setCustomNameVisible(true);
entity.setCustomName("§c" + userName);
@ -102,7 +100,6 @@ public class SummonTheCow {
}
if(amount <= 0){
entity.damage(999.0D);
cancel();
return;
}
// 检测村民是否存在任务 若存在则抵达目标方块时触发消息 已完成任务
@ -111,22 +108,28 @@ public class SummonTheCow {
if (locationMap.containsKey(uuid)) {
Location location1 = locationMap.get(uuid);
if (entity.getLocation().distance(location1) <= 1.0) {
amount--;
if(locationMap.size() > 10) {
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);
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
Block block = location.getWorld().getBlockAt(location1.clone().add(x, 0, z));
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);
}
}
block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 1, 0.5), 5, 0.5, 0.5, 0.5, 0.1);
}
}
}
@ -143,8 +146,6 @@ public class SummonTheCow {
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]");
}

View File

@ -0,0 +1,159 @@
package com.yaohun.wheatwar.effect;
import com.yaohun.wheatwar.WheatWar;
import com.yaohun.wheatwar.game.Game;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import tools.CDTimeAPI;
import tools.RandomUtil;
import java.util.HashMap;
import java.util.UUID;
public class SummonTheSheepPro {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {
return;
}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "SummonSheepProEffect";
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);
Sheep entity = (Sheep) location.getWorld().spawnEntity(location, EntityType.SHEEP);
DyeColor dyeColor = DyeColor.values()[14];
entity.setColor(dyeColor);
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 color = 0;
private int amount = 50;
@Override
public void run() {
UUID uuid = entity.getUniqueId();
// 若村民死亡则计时器种植并结束村民任务
if (entity.isDead()) {
locationMap.remove(uuid);
cancel();
return;
}
if(amount <= 0){
entity.damage(999.0D);
return;
}
// 检测村民是否存在任务 若存在则抵达目标方块时触发消息 已完成任务
//
// 若村民没有任务则获取坐标后通过NMS设置村民寻路目标坐标 并put添加任务
if (locationMap.containsKey(uuid)) {
Location location1 = locationMap.get(uuid);
if (entity.getLocation().distance(location1) <= 1.0) {
amount--;
//到达目标小麦位置
locationMap.remove(uuid);
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
Block block = location.getWorld().getBlockAt(location1.clone().add(x, 0, z));
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.45);
entity.setVelocity(velocity);
}
} else {
// 优先寻找未种小麦的地 已种小麦未成熟的地 坐标
Location location1 = game.getPriorityClearLocation();
if(location1 == null){
Bukkit.broadcastMessage("!游戏结束!路人获胜!");
cancel();
return;
}
locationMap.put(uuid, location1);
entity.setCustomName("§c" + userName+" [§6"+amount+"§c]");
}
if(color > 5) {
DyeColor dyeColor = DyeColor.values()[RandomUtil.getRandomInt(7, 15)];
entity.setColor(dyeColor);
color -= 5;
}
color++;
}
}.runTaskTimer(WheatWar.inst(), 20L, 1L);
}
}

View File

@ -0,0 +1,86 @@
package com.yaohun.wheatwar.effect;
import com.yaohun.wheatwar.WheatWar;
import com.yaohun.wheatwar.game.Game;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.*;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import tools.CDTimeAPI;
import tools.RandomUtil;
import java.util.UUID;
public class SummonTheTNTRain {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {
return;
}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "SummonRainTNTEffect";
startTimepieceEvent(game,zhubo,userName,timepieceKey);
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (195L * amount);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,195L * 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);
spawnMobs(game);
if(RandomUtil.getRandomInt(1,100) >= 70) {
zhubo.playSound(zhubo.getLocation(), "youbom", 1, 1);
}
}
}.runTaskTimer(WheatWar.inst(), 0L, 5L);
game.addTasks(task);
}
public static void spawnMobs(Game game) {
Location location = game.getFarmlandRandom().clone().add(0,1,0);
TNTPrimed entity = (TNTPrimed) game.getWorld().spawn(location, TNTPrimed.class);
// 设置爆炸范围和伤害监听器
entity.setYield(3.0F); // 爆炸范围默认值为 4.0F
entity.setIsIncendiary(false); // 如果需要爆炸引起火焰可设置为 true
entity.setFuseTicks(40); // 设置2秒后爆炸1秒=20 ticks
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);
i++;
}
}.runTaskTimer(WheatWar.inst(),0,1L);
}
}

View File

@ -2,12 +2,10 @@ 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.*;
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;
@ -100,7 +98,6 @@ public class SummonTheVillager {
}
if(amount <= 0){
entity.damage(999.0D);
cancel();
return;
}
// 检测村民是否存在任务 若存在则抵达目标方块时触发消息 已完成任务
@ -109,26 +106,31 @@ public class SummonTheVillager {
if (locationMap.containsKey(uuid)) {
Location location1 = locationMap.get(uuid);
if (entity.getLocation().distance(location1) <= 1.0) {
amount--;
if(locationMap.size() > 15) {
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);
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
Block block = location.getWorld().getBlockAt(location1.clone().add(x, 0, z));
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);
}
}
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();
@ -143,11 +145,10 @@ public class SummonTheVillager {
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]");
}
entity.setProfession(Villager.Profession.FARMER);
}
}.runTaskTimer(WheatWar.inst(), 20L, 1L);
}

View File

@ -0,0 +1,155 @@
package com.yaohun.wheatwar.effect;
import com.yaohun.wheatwar.WheatWar;
import com.yaohun.wheatwar.game.Game;
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.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 SummonTheVillagerPro {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {
return;
}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "SummonVillagerProEffect";
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);
Villager entity = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
entity.setCollidable(false);
entity.setCustomNameVisible(true);
entity.setCustomName("§b" + userName);
entity.setHealth(2);
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);
i++;
}
}.runTaskTimer(WheatWar.inst(),0,1L);
new BukkitRunnable() {
private int amount = 50;
@Override
public void run() {
UUID uuid = entity.getUniqueId();
// 若村民死亡则计时器种植并结束村民任务
if (entity.isDead()) {
locationMap.remove(uuid);
cancel();
return;
}
if(amount <= 0){
entity.damage(999.0D);
return;
}
// 检测村民是否存在任务 若存在则抵达目标方块时触发消息 已完成任务
//
// 若村民没有任务则获取坐标后通过NMS设置村民寻路目标坐标 并put添加任务
if (locationMap.containsKey(uuid)) {
Location location1 = locationMap.get(uuid);
if (entity.getLocation().distance(location1) <= 1.0) {
amount--;
//到达目标小麦位置
locationMap.remove(uuid);
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
Block block = location.getWorld().getBlockAt(location1.clone().add(x, 0, z));
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.45);
entity.setVelocity(velocity);
}
} else {
// 优先寻找未种小麦的地 已种小麦未成熟的地 坐标
Location location1 = game.getPriorityRepairLocation();
if(location1 == null){
Bukkit.broadcastMessage("!游戏结束!村民获胜!");
cancel();
return;
}
locationMap.put(uuid, location1);
entity.setCustomName("§b" + userName+"[§6"+amount+"§b]");
}
entity.setProfession(Villager.Profession.ARMORER);
}
}.runTaskTimer(WheatWar.inst(), 20L, 1L);
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -11,7 +10,6 @@ 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;