测试版
This commit is contained in:
parent
23d054922b
commit
88f8dd6fcb
|
@ -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;}
|
||||
}
|
||||
|
|
65
src/main/java/com/yaohun/wheatwar/data/GiftData.java
Normal file
65
src/main/java/com/yaohun/wheatwar/data/GiftData.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
48
src/main/java/com/yaohun/wheatwar/data/LikeData.java
Normal file
48
src/main/java/com/yaohun/wheatwar/data/LikeData.java
Normal 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);
|
||||
}
|
||||
}
|
255
src/main/java/com/yaohun/wheatwar/data/RepairGiftGui.java
Normal file
255
src/main/java/com/yaohun/wheatwar/data/RepairGiftGui.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,11 +108,15 @@ public class SummonTheCow {
|
|||
if (locationMap.containsKey(uuid)) {
|
||||
Location location1 = locationMap.get(uuid);
|
||||
if (entity.getLocation().distance(location1) <= 1.0) {
|
||||
if(locationMap.size() > 10) {
|
||||
amount--;
|
||||
}
|
||||
//到达目标小麦位置
|
||||
locationMap.remove(uuid);
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
|
||||
Block block = location.getWorld().getBlockAt(location1);
|
||||
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();
|
||||
|
@ -130,6 +131,8 @@ public class SummonTheCow {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Vector direction = location1.toVector().subtract(entity.getLocation().toVector()).normalize();
|
||||
Vector velocity = direction.multiply(0.25);
|
||||
|
@ -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]");
|
||||
}
|
159
src/main/java/com/yaohun/wheatwar/effect/SummonTheSheepPro.java
Normal file
159
src/main/java/com/yaohun/wheatwar/effect/SummonTheSheepPro.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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,11 +106,14 @@ public class SummonTheVillager {
|
|||
if (locationMap.containsKey(uuid)) {
|
||||
Location location1 = locationMap.get(uuid);
|
||||
if (entity.getLocation().distance(location1) <= 1.0) {
|
||||
if(locationMap.size() > 15) {
|
||||
amount--;
|
||||
}
|
||||
//到达目标小麦位置
|
||||
locationMap.remove(uuid);
|
||||
// 获取这个坐标的方块数据是未种小麦还是未成熟小麦
|
||||
Block block = location.getWorld().getBlockAt(location1);
|
||||
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();
|
||||
|
@ -130,6 +130,8 @@ public class SummonTheVillager {
|
|||
}
|
||||
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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.yaohun.wheatwar.game;
|
||||
|
||||
import com.io.yutian.pixelliveengine.api.PixelLiveEngineAPI;
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.data.LikeData;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
|
@ -8,15 +10,17 @@ import org.bukkit.block.data.BlockData;
|
|||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import tools.BossBarUtil;
|
||||
import tools.StackUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
public class Game {
|
||||
|
||||
|
@ -24,17 +28,20 @@ public class Game {
|
|||
private Region region;
|
||||
private BossBar bossBar1;
|
||||
private BossBar bossBar2;
|
||||
private BossBar bossBar3;
|
||||
private boolean started = false;
|
||||
private Location centralPoint;
|
||||
private List<Location> wheatList = new ArrayList<>();
|
||||
private List<BukkitTask> tasks = new ArrayList<>();
|
||||
// 狂暴模式
|
||||
public Game(){
|
||||
this.world = Bukkit.getWorld("world");
|
||||
this.region = new Region(world,new Point(-30,68,-33),new Point(32,68,29));
|
||||
this.centralPoint = new Location(world,1,72,-2);
|
||||
this.bossBar1 = Bukkit.createBossBar("今日挑战进度", BarColor.WHITE, BarStyle.SEGMENTED_10);
|
||||
this.bossBar2 = Bukkit.createBossBar("补种进度", BarColor.GREEN, BarStyle.SEGMENTED_20);
|
||||
loadGameMapFarmland();
|
||||
this.bossBar3 = Bukkit.createBossBar("点赞累积数量", BarColor.WHITE, BarStyle.SEGMENTED_10);
|
||||
initGameMapFarmland();
|
||||
}
|
||||
|
||||
private void updateCompleteWheatGoalBossBar() {
|
||||
|
@ -47,6 +54,26 @@ public class Game {
|
|||
BossBarUtil.setBarProgress(bossBar2,d);
|
||||
}
|
||||
|
||||
public void updateDianZanBossBar() {
|
||||
int dz = 0;
|
||||
int needDz = 300;
|
||||
String eventName = "";
|
||||
HashMap<String, LikeData> likeDataMap = WheatWar.getGameManager().getLikeDataMap();
|
||||
for (String key : likeDataMap.keySet()){
|
||||
LikeData likeData = likeDataMap.get(key);
|
||||
dz = likeData.getNowAmount();
|
||||
needDz = likeData.getNeedAmount();
|
||||
eventName = likeData.getEffectKey();
|
||||
break;
|
||||
}
|
||||
int dz_need = needDz;
|
||||
double dz1 = (double) dz / (double) dz_need;
|
||||
// String bossTitle = "§6"+eventName+"(戳一戳): §d"+dz+"§f/§c"+dz_need;
|
||||
String bossTitle = "§9§l"+eventName+"§6: §d"+dz+"§f/§c"+dz_need;
|
||||
bossBar3.setTitle(bossTitle);
|
||||
BossBarUtil.setBarColor(bossBar3,dz1);
|
||||
BossBarUtil.setBarProgress(bossBar3,dz1);
|
||||
}
|
||||
|
||||
|
||||
public void start(){
|
||||
|
@ -58,16 +85,53 @@ public class Game {
|
|||
@Override
|
||||
public void run() {
|
||||
updateCompleteWheatGoalBossBar();
|
||||
updateDianZanBossBar();
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(), 0L, 5L));
|
||||
}
|
||||
|
||||
public int getWorldEntityAmount(EntityType entityType){
|
||||
int amount = 0;
|
||||
for (Entity entity : this.world.getEntities()){
|
||||
if(entity.getType().equals(entityType)){
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void initPlayerData(Player player) {
|
||||
player.setArrowCooldown(6000);
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.setAllowFlight(true);
|
||||
// bossBar1.addPlayer(player);
|
||||
bossBar2.addPlayer(player);
|
||||
bossBar3.addPlayer(player);
|
||||
initPlayerBackpack(player);
|
||||
/*tasks.add(new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(player == null || !player.isOnline()){
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
refreshHudMessage(player);
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(), 0L, 5L));*/
|
||||
}
|
||||
public void refreshHudMessage(Player player){
|
||||
PixelLiveEngineAPI.clearHudText();
|
||||
List<String> stringList = new ArrayList<>();
|
||||
stringList.add("§c小羊哥: §f"+getWorldEntityAmount(EntityType.SHEEP)+"只");
|
||||
stringList.add("§b村民: §f"+getWorldEntityAmount(EntityType.VILLAGER)+"名");
|
||||
PixelLiveEngineAPI.setHudText(stringList);
|
||||
}
|
||||
public void initPlayerBackpack(Player player){
|
||||
Inventory inv = player.getInventory();
|
||||
inv.setItem(0, StackUtil.diamondSword());
|
||||
inv.setItem(1,StackUtil.trident());
|
||||
inv.setItem(2,new ItemStack(Material.WHEAT_SEEDS,32));
|
||||
inv.setItem(3,new ItemStack(Material.BONE_MEAL,32));
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,7 +250,15 @@ public class Game {
|
|||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
public void loadGameMapFarmland(){
|
||||
public void initGameMapFarmland(){
|
||||
this.world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
this.world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
this.world.setGameRule(GameRule.DO_MOB_SPAWNING, false);
|
||||
this.world.setGameRule(GameRule.DO_MOB_LOOT, false);
|
||||
this.world.setGameRule(GameRule.MOB_GRIEFING, false);
|
||||
this.world.setGameRule(GameRule.RANDOM_TICK_SPEED, 0);
|
||||
this.world.setTime(4500);
|
||||
this.world.setDifficulty(Difficulty.NORMAL);
|
||||
List<Location> locationList = new ArrayList<>();
|
||||
for (int y = (int) Math.floor(67); y <= 67; y++) {
|
||||
for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) {
|
||||
|
|
|
@ -1,22 +1,44 @@
|
|||
package com.yaohun.wheatwar.listener;
|
||||
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.effect.SummonTheZombie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Farmland;
|
||||
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.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class GameListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPingMotd(ServerListPingEvent e){
|
||||
if(WheatWar.getGame().isStarted()){
|
||||
e.setMotd("§a整蛊模式: §6小麦保卫战 §a当前版本: §6常规版 §b运行中");
|
||||
} else {
|
||||
e.setMotd("§a整蛊模式: §6小麦保卫战 §a当前版本: §6常规版 §b运行中");
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<UUID,UUID> zombieTargetMap = new HashMap<>();
|
||||
@EventHandler
|
||||
public void onZombieTarget(EntityTargetEvent event) {
|
||||
// 检查是否是僵尸
|
||||
if (event.getEntityType() == EntityType.ZOMBIE_VILLAGER) {
|
||||
// 检查目标是否是玩家
|
||||
if (event.getTarget() instanceof Player) {
|
||||
// 取消该事件以阻止僵尸将玩家设为仇恨目标
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
// 检查是否是僵尸
|
||||
if (event.getEntityType() == EntityType.ZOMBIE) {
|
||||
// 检查目标是否是玩家
|
||||
|
@ -24,16 +46,6 @@ public class GameListener implements Listener {
|
|||
// 取消该事件以阻止僵尸将玩家设为仇恨目标
|
||||
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);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,4 +70,29 @@ public class GameListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<UUID> whiteListTNT = new ArrayList<>();
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageByEntityEvent e){
|
||||
if(e.getDamager() instanceof TNTPrimed tntPrimed){
|
||||
Entity entity = e.getEntity();
|
||||
if(entity instanceof ZombieVillager){
|
||||
e.setDamage(1000.0D);
|
||||
} else if(entity instanceof Zombie){
|
||||
e.setDamage(1000.0D);
|
||||
} else {
|
||||
if(whiteListTNT.contains(tntPrimed.getUniqueId())){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Block block = iterator.next();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,23 @@ import org.bukkit.Material;
|
|||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class GamePotect implements Listener {
|
||||
@EventHandler // 取消生物燃烧
|
||||
|
@ -59,4 +65,17 @@ public class GamePotect implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBreak(BlockBreakEvent e){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@EventHandler
|
||||
public void onDrop(PlayerDropItemEvent e){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent e){
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
package com.yaohun.wheatwar.listener;
|
||||
|
||||
import com.io.yutian.pixelliveengine.api.PixelLiveEngineAPI;
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.data.RepairGiftGui;
|
||||
import com.yaohun.wheatwar.game.Game;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import tools.RandomUtil;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
Player player = e.getPlayer();
|
||||
Game game = WheatWar.getGame();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
|
@ -18,8 +26,63 @@ public class JoinListener implements Listener {
|
|||
if(!game.isStarted()) {
|
||||
game.start();
|
||||
}
|
||||
player.teleport(new Location(player.getWorld(),3.5,68,32.5,-180,0));
|
||||
game.initPlayerData(e.getPlayer());
|
||||
}
|
||||
}.runTaskLater(WheatWar.inst(),10L);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PixelLiveEngineAPI.loadResourcePack("SoundPack5","rvHbB9FdOxWYAfi8kTLe");
|
||||
}
|
||||
}.runTaskLater(WheatWar.inst(),20L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPick(PlayerDropItemEvent e){
|
||||
Player p = e.getPlayer();
|
||||
if (WheatWar.getGame().isStarted()) {
|
||||
if(p.isSneaking()){
|
||||
RepairGiftGui.OpenGui(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAutoRespawn(PlayerDeathEvent e) {
|
||||
e.setDeathMessage(null);
|
||||
Player p = e.getEntity();
|
||||
// 获取当前游戏记录点高度
|
||||
Game game = WheatWar.getGame();
|
||||
if (game.isStarted()) {
|
||||
new BukkitRunnable() {
|
||||
private int i = 0;
|
||||
|
||||
public void run() {
|
||||
if (i == 1) {
|
||||
p.spigot().respawn();
|
||||
}
|
||||
if(i == 3){
|
||||
p.getInventory().clear();
|
||||
}
|
||||
if(i == 4) {
|
||||
if (RandomUtil.getRandomInt(1,100) >= 50) {
|
||||
p.sendTitle("§4你嘎了", "行不行啊?菜就多练!");
|
||||
} else {
|
||||
p.sendTitle("§4你嘎了", "汗流浃背了?");
|
||||
}
|
||||
game.initPlayerBackpack(p);
|
||||
}
|
||||
if(i == 5) {
|
||||
p.teleport(new Location(p.getWorld(),3.5,68,32.5,-180,0));
|
||||
if(!p.getAllowFlight()){
|
||||
p.setAllowFlight(true);
|
||||
}
|
||||
cancel();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}.runTaskTimer(WheatWar.inst(),0L, 2L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.yaohun.wheatwar.liveevent;
|
||||
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.effect.*;
|
||||
import com.yaohun.wheatwar.game.Game;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import tools.GameUtil;
|
||||
import tools.RandomUtil;
|
||||
|
||||
public class GiftEventHandler {
|
||||
|
||||
public static void SendHandLer(Player zhubo, String userName, String eventName){
|
||||
Game game = WheatWar.getGame();
|
||||
userName = GameUtil.hideName(userName);
|
||||
if (eventName.contains("小羊哥")) {
|
||||
int amount = 1;
|
||||
if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
|
||||
eventName = eventName.replace("*","X");
|
||||
String[] eventSp = eventName.toUpperCase().split("X");
|
||||
amount = Integer.parseInt(eventSp[1]);
|
||||
}
|
||||
SummonTheSheep.apply(game, zhubo, userName, amount);
|
||||
} else if (eventName.contains("小红羊")) {
|
||||
int amount = 1;
|
||||
if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
|
||||
eventName = eventName.replace("*","X");
|
||||
String[] eventSp = eventName.toUpperCase().split("X");
|
||||
amount = Integer.parseInt(eventSp[1]);
|
||||
}
|
||||
SummonTheSheepPro.apply(game, zhubo, userName, amount);
|
||||
} else if (eventName.contains("暴躁村民")) {
|
||||
int amount = 1;
|
||||
if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
|
||||
eventName = eventName.replace("*","X");
|
||||
String[] eventSp = eventName.toUpperCase().split("X");
|
||||
amount = Integer.parseInt(eventSp[1]);
|
||||
}
|
||||
SummonTheVillagerPro.apply(game, zhubo, userName, amount);
|
||||
}else if (eventName.contains("村民")) {
|
||||
int amount = 1;
|
||||
if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
|
||||
eventName = eventName.replace("*","X");
|
||||
String[] eventSp = eventName.toUpperCase().split("X");
|
||||
amount = Integer.parseInt(eventSp[1]);
|
||||
}
|
||||
SummonTheVillager.apply(game, zhubo, userName, amount);
|
||||
} else if (eventName.contains("僵尸")) {
|
||||
int amount = 1;
|
||||
if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
|
||||
eventName = eventName.replace("*","X");
|
||||
String[] eventSp = eventName.toUpperCase().split("X");
|
||||
amount = Integer.parseInt(eventSp[1]);
|
||||
}
|
||||
SummonTheZombie.apply(game, zhubo, userName, amount);
|
||||
} else if (eventName.contains("炸弹")) {
|
||||
int amount = 1;
|
||||
if(eventName.contains("X") || eventName.contains("x") || eventName.contains("*")) {
|
||||
eventName = eventName.replace("*","X");
|
||||
String[] eventSp = eventName.toUpperCase().split("X");
|
||||
amount = Integer.parseInt(eventSp[1]);
|
||||
}
|
||||
SummonTheBombsTNT.apply(game, zhubo, userName, amount);
|
||||
} else if (eventName.equalsIgnoreCase("无差别轰炸")) {
|
||||
SummonTheTNTRain.apply(game,zhubo,userName,50);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.yaohun.wheatwar.liveevent;
|
||||
|
||||
import com.io.yutian.mclive.event.LiveGiftEvents;
|
||||
import com.yaohun.wheatwar.util.GiftUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import tools.GameUtil;
|
||||
import tools.RandomUtil;
|
||||
|
||||
public class GiftListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onGfit(LiveGiftEvents e) {
|
||||
Player zhubo = e.getPlayer();
|
||||
String userName = ""+ RandomUtil.getRandomInt(10000,90000);
|
||||
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;
|
||||
}
|
||||
String show_userName = GameUtil.hideName(userName);
|
||||
GiftUtil.simulatedGiftEffect(zhubo,show_userName,giftName,amount);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.yaohun.wheatwar.liveevent;
|
||||
|
||||
import com.io.yutian.mclive.event.LiveChatEvents;
|
||||
import com.io.yutian.mclive.event.LiveLikeEvents;
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.data.LikeData;
|
||||
import com.yaohun.wheatwar.manage.GameManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
import tools.CDTimeAPI;
|
||||
import tools.RandomUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class LikeListener implements Listener {
|
||||
|
||||
private GameManager gameManager;
|
||||
public LikeListener(GameManager manager){
|
||||
gameManager = manager;
|
||||
}
|
||||
@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();
|
||||
HashMap<String, LikeData> likeDataMap = gameManager.getLikeDataMap();
|
||||
for (String key : likeDataMap.keySet()){
|
||||
LikeData likeData = likeDataMap.get(key);
|
||||
likeData.addNowAmount((int)add_amount);
|
||||
dropLikeEffect(zhubo, (int) add_amount);
|
||||
if(likeData.meetTheQuantityRequirement()){
|
||||
String eventName = likeData.getEffectKey();
|
||||
String title = "§c";
|
||||
String subtitle = "§c("+eventName+") §f- §9"+likeData.getNeedAmount()+"个戳一戳";
|
||||
// String subtitle = "§r";
|
||||
likeData.OutPlaySoundsEvent();
|
||||
zhubo.sendTitle(title, subtitle,0, 30, 10);
|
||||
GiftEventHandler.SendHandLer(zhubo,userName,eventName);
|
||||
likeData.setNowAmount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dropLikeEffect(Player zhubo,int amount) {
|
||||
List<ItemStack> stackList = new ArrayList<>();
|
||||
stackList.add(getLikeStack(251));
|
||||
stackList.add(getLikeStack(252));
|
||||
stackList.add(getLikeStack(253));
|
||||
stackList.add(getLikeStack(254));
|
||||
stackList.add(getLikeStack(255));
|
||||
stackList.add(getLikeStack(256));
|
||||
stackList.add(getLikeStack(257));
|
||||
for (int i = 0; i < amount; i++) {
|
||||
Bukkit.getScheduler().runTaskLater(WheatWar.inst(), () -> {
|
||||
int rand = RandomUtil.getRandomInt(0, stackList.size() - 1);
|
||||
ItemStack stack = stackList.get(rand);
|
||||
Item item = zhubo.getWorld().dropItem(zhubo.getLocation().add(0,1,0), stack);
|
||||
item.setVelocity(item.getLocation().getDirection().multiply(0.25D));
|
||||
item.setVelocity(new Vector(item.getVelocity().getX(), 0.4D, item.getVelocity().getZ()));
|
||||
Bukkit.getScheduler().runTaskLater(WheatWar.inst(), item::remove, (long) 60);
|
||||
}, (long) i * 5);
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getLikeStack(int modelId){
|
||||
ItemStack item = new ItemStack(Material.SUGAR);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("#"+RandomUtil.getRandomInt(999,100000));
|
||||
meta.setLore(lore);
|
||||
meta.setCustomModelData(modelId);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
70
src/main/java/com/yaohun/wheatwar/manage/GameManager.java
Normal file
70
src/main/java/com/yaohun/wheatwar/manage/GameManager.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package com.yaohun.wheatwar.manage;
|
||||
|
||||
import com.io.yutian.mclive.event.ZhuboAPI;
|
||||
import com.yaohun.wheatwar.data.GiftData;
|
||||
import com.yaohun.wheatwar.data.LikeData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GameManager {
|
||||
private File manageFile;
|
||||
private FileConfiguration manageConfig;
|
||||
private HashMap<String, LikeData> likeDataMap = new HashMap<>();
|
||||
private HashMap<String, GiftData> giftDataMap = new HashMap<>();
|
||||
private static boolean isRandomBox;
|
||||
public GameManager(){
|
||||
Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 工具注册:");
|
||||
loadRandomBoxPlugin();
|
||||
Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 游戏设置:");
|
||||
loadSettingsData();
|
||||
Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 事件注册:");
|
||||
File file = new File("./plugins/游戏设置","礼物设置.yml");
|
||||
FileConfiguration gift_yml = YamlConfiguration.loadConfiguration(file);
|
||||
ConfigurationSection likeSection = gift_yml.getConfigurationSection("点赞整蛊");
|
||||
if (likeSection != null) {
|
||||
for (String key : likeSection.getKeys(false)) {
|
||||
String effect = likeSection.getString(key+".效果");
|
||||
int likeAmount = likeSection.getInt(key+".点赞次数");
|
||||
String likesounds = likeSection.getString(key+".声音","wau");
|
||||
likeDataMap.put(effect,new LikeData(effect,likeAmount,likesounds));
|
||||
String message = "事件: "+effect+" 条件: 点赞x"+likeAmount;
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
}
|
||||
}
|
||||
ConfigurationSection giftSection = gift_yml.getConfigurationSection("礼物设置");
|
||||
if(giftSection != null){
|
||||
ZhuboAPI.setGameGiftList(new ArrayList<>(giftSection.getKeys(false)));
|
||||
for (String giftName : giftSection.getKeys(false)) {
|
||||
giftDataMap.put(giftName, new GiftData(giftName, gift_yml));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadSettingsData(){
|
||||
manageFile = new File("./plugins/游戏设置","游戏设置.yml");
|
||||
manageConfig = YamlConfiguration.loadConfiguration(manageFile);
|
||||
}
|
||||
|
||||
public void loadRandomBoxPlugin() {
|
||||
if(Bukkit.getPluginManager().getPlugin("RandomBox") != null){
|
||||
isRandomBox = true;
|
||||
Bukkit.getConsoleSender().sendMessage("- 随机盲盒: 已启用");
|
||||
} else {
|
||||
isRandomBox = false;
|
||||
Bukkit.getConsoleSender().sendMessage("- 随机盲盒: 未启用");
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, LikeData> getLikeDataMap() {return likeDataMap;}
|
||||
public boolean isGiftDataExit(String giftName){for (String gift : this.giftDataMap.keySet()){if(gift.equalsIgnoreCase(giftName)){return true;}}return false;}
|
||||
public GiftData getGiftData(String giftName){if(this.giftDataMap.get(giftName) == null){return null;}return this.giftDataMap.get(giftName);}
|
||||
public HashMap<String, GiftData> getGiftDataMap() {
|
||||
return giftDataMap;
|
||||
}
|
||||
}
|
75
src/main/java/com/yaohun/wheatwar/util/GiftUtil.java
Normal file
75
src/main/java/com/yaohun/wheatwar/util/GiftUtil.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package com.yaohun.wheatwar.util;
|
||||
|
||||
import com.yaohun.wheatwar.WheatWar;
|
||||
import com.yaohun.wheatwar.data.GiftData;
|
||||
import com.yaohun.wheatwar.liveevent.GiftEventHandler;
|
||||
import com.yaohun.wheatwar.manage.GameManager;
|
||||
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(specialGiftEffectTriggers(player,eventName,userName,amount)){
|
||||
return;
|
||||
}
|
||||
GiftEventHandler.SendHandLer(player, userName, eventName);
|
||||
}
|
||||
public static void simulatedGiftEffect(Player player, String userName, String giftName, int amount){
|
||||
GameManager manager = WheatWar.getGameManager();
|
||||
if(!manager.isGiftDataExit(giftName)){
|
||||
return;
|
||||
}
|
||||
GiftData giftData = manager.getGiftData(giftName);
|
||||
giftData.OutCompleEvent(amount);
|
||||
String eventName = giftData.getEvent();
|
||||
if(GiftUtil.specialGiftEffectTriggers(player,eventName,userName,amount)){
|
||||
giftData.OutPlaySoundsEvent();
|
||||
return;
|
||||
}
|
||||
String title = "§c" + eventName;
|
||||
if(amount >= 2) {
|
||||
title = "§c" + eventName + " x" + amount;
|
||||
}
|
||||
String subtitle = "§9" + giftName;
|
||||
player.sendTitle(title, subtitle,0, 30, 10);
|
||||
if (amount <= 1) {
|
||||
giftData.OutPlaySoundsEvent();
|
||||
GiftEventHandler.SendHandLer(player, userName, eventName);
|
||||
} else {
|
||||
long dadey = 5L;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
Bukkit.getScheduler().runTaskLater(WheatWar.inst(), giftData::OutPlaySoundsEvent, (long) i * dadey);
|
||||
}
|
||||
for (int i = 0; i < amount; i++) {
|
||||
GiftEventHandler.SendHandLer(player, userName, eventName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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[] eventSp = eventName.split("#");
|
||||
String boxKey = eventSp[1];
|
||||
int boxAmount = 1;
|
||||
if (boxKey.contains("X")) {
|
||||
boxAmount = Integer.parseInt(boxKey.split("X")[1]);
|
||||
boxKey = s1 + "-" + s2 + "-" + boxKey.split("X")[0];
|
||||
} else if (boxKey.contains("x")) {
|
||||
boxAmount = Integer.parseInt(boxKey.split("x")[1]);
|
||||
boxKey = s1 + "-" + s2 + "-" + boxKey.split("x")[0];
|
||||
} else {
|
||||
boxKey = s1 + "-" + s2 + "-" + boxKey;
|
||||
}
|
||||
amount = (boxAmount * amount);
|
||||
// RBoxAPI.addUserData(player, show_userName, boxKey, amount);
|
||||
} else {
|
||||
System.out.println("[错误 - 盲盒] 随机盲盒在礼物设置中配置错误.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -13,5 +13,32 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class StackUtil {
|
||||
|
||||
public static ItemStack diamondSword(){
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
|
||||
int randint = RandomUtil.getRandomInt(0,100);
|
||||
if(randint >= 50){
|
||||
item.setType(Material.NETHERITE_SWORD);
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("§6§l农夫的神剑");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7#极光像素工作室制作");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
meta.setUnbreakable(true);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
public static ItemStack trident(){
|
||||
ItemStack item = new ItemStack(Material.TRIDENT);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("§6§l三叉戟");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7#极光像素工作室制作");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
meta.setUnbreakable(true);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user