This commit is contained in:
yaohunya 2024-09-19 21:56:11 +08:00
parent 97f617a993
commit 7083ff6c6b
12 changed files with 648 additions and 56 deletions

View File

@ -4,6 +4,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.yaohun.farmingwar.data.GameEditGui;
import com.yaohun.farmingwar.data.RepairGiftGui; import com.yaohun.farmingwar.data.RepairGiftGui;
import com.yaohun.farmingwar.game.Game; import com.yaohun.farmingwar.game.Game;
import com.yaohun.farmingwar.game.Point; import com.yaohun.farmingwar.game.Point;
@ -34,7 +35,8 @@ public class FarmingWar extends JavaPlugin {
public void onEnable() { public void onEnable() {
instance = this; instance = this;
gameManager = new GameManager(); gameManager = new GameManager();
game = new Game(); game = new Game(gameManager);
Bukkit.getPluginManager().registerEvents(new GameEditGui(game), this);
Bukkit.getPluginManager().registerEvents(new RepairGiftGui(), this); Bukkit.getPluginManager().registerEvents(new RepairGiftGui(), this);
Bukkit.getPluginManager().registerEvents(new GiftListener(), this); Bukkit.getPluginManager().registerEvents(new GiftListener(), this);
Bukkit.getPluginManager().registerEvents(new LikeListener(gameManager), this); Bukkit.getPluginManager().registerEvents(new LikeListener(gameManager), this);
@ -46,12 +48,26 @@ public class FarmingWar extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new KeepEntitiesOnDeath(), this); Bukkit.getPluginManager().registerEvents(new KeepEntitiesOnDeath(), this);
} }
@Override
public void onDisable() {
gameManager.saveGameSettings();
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("livegift")) {
RepairGiftGui.OpenGui((Player) sender);
return true;
}
if (label.equalsIgnoreCase("gameedit")) {
GameEditGui.OpenGui((Player) sender);
return true;
}
if (label.equalsIgnoreCase("game")) {
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage("/game start - 开始游戏"); sender.sendMessage("/game start - 开始游戏");
return true; return true;
}else { } else {
String subCommand = args[0]; String subCommand = args[0];
if (subCommand.equalsIgnoreCase("start")) { if (subCommand.equalsIgnoreCase("start")) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
@ -78,23 +94,24 @@ public class FarmingWar extends JavaPlugin {
Point minPoint = new Point(min.getBlockX(), min.getBlockY(), min.getBlockZ()); Point minPoint = new Point(min.getBlockX(), min.getBlockY(), min.getBlockZ());
Point maxPoint = new Point(max.getBlockX(), max.getBlockY(), max.getBlockZ()); Point maxPoint = new Point(max.getBlockX(), max.getBlockY(), max.getBlockZ());
Region region1 = new Region(player.getWorld(), minPoint, maxPoint); Region region1 = new Region(player.getWorld(), minPoint, maxPoint);
game.createRegion(regionKey,region1); game.createRegion(regionKey, region1);
player.sendMessage("区域创建成功."); player.sendMessage("区域创建成功.");
} else if(args.length == 2 && args[0].equalsIgnoreCase("effect")){ } else if (args.length == 2 && args[0].equalsIgnoreCase("effect")) {
List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers()); List<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
Player player = players.get(0); Player player = players.get(0);
if(sender instanceof Player){ if (sender instanceof Player) {
player = (Player) sender; player = (Player) sender;
} }
String eventName = args[1]; String eventName = args[1];
String userName = "观众"+ RandomUtil.getRandomInt(0,10); String userName = "观众" + RandomUtil.getRandomInt(0, 10);
String title = "§c" + eventName; String title = "§c" + eventName;
String subtitle = "§9" + GameUtil.hideName(userName); String subtitle = "§9" + GameUtil.hideName(userName);
player.sendTitle(title, subtitle,10, 30, 10); player.sendTitle(title, subtitle, 10, 30, 10);
GiftEventHandler.SendHandLer(player,userName,eventName); GiftEventHandler.SendHandLer(player, userName, eventName);
return true; return true;
} }
} }
}
return false; return false;
} }

View File

@ -0,0 +1,361 @@
package com.yaohun.farmingwar.data;
import com.yaohun.farmingwar.FarmingWar;
import com.yaohun.farmingwar.game.Game;
import com.yaohun.farmingwar.manager.GameManager;
import com.yaohun.farmingwar.util.BackPointType;
import de.tr7zw.nbtapi.NBTItem;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
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.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import tools.BossBarUtil;
import tools.CDTimeAPI;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class GameEditGui implements Listener {
public static String invTitle = "我的世界整蛊 - 游戏设置管理";
private Game game;
public GameEditGui(Game gameMain){
game = gameMain;
}
@EventHandler
public void onClick(InventoryClickEvent e){
int rawSlot = e.getRawSlot();
Player zhubo = (Player) e.getWhoClicked();
ItemStack item = e.getCurrentItem();
if(e.getView().getTitle().equalsIgnoreCase(invTitle)){
e.setCancelled(true);
if(item == null || item.getType() == Material.AIR){
return;
}
GameManager gameManager = FarmingWar.getGameManager();
if(rawSlot == 0){
zhubo.closeInventory();
if(e.getClick() == ClickType.LEFT){
game.addBossBar(zhubo,game.getBossBar1());
}else if(e.getClick() == ClickType.RIGHT){
game.removeBossBar(zhubo,game.getBossBar1());
}
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
GameEditGui.OpenGui(zhubo);
}
if(rawSlot == 2){
zhubo.closeInventory();
if(e.getClick() == ClickType.LEFT){
game.addBossBar(zhubo,game.getBossBar2());
}else if(e.getClick() == ClickType.RIGHT){
game.removeBossBar(zhubo,game.getBossBar2());
}
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
GameEditGui.OpenGui(zhubo);
}
if(rawSlot == 4){
if(e.getClick() == ClickType.LEFT){
long nowTime = gameManager.getGameTime()+500;
if(nowTime >= 18000){
nowTime = 18000;
}
gameManager.setGameTime(nowTime);
} else if(e.getClick() == ClickType.RIGHT){
long nowTime = gameManager.getGameTime()-500;
if(nowTime <= 1000){
nowTime = 1000;
}
gameManager.setGameTime(nowTime);
}
zhubo.getWorld().setTime(gameManager.getGameTime());
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
GameEditGui.OpenGui(zhubo);
}
if(rawSlot == 8){
zhubo.closeInventory();
int amount = 0;
for (CDTimeAPI.CDData data : CDTimeAPI.getCdData()) {
for (String key : data.getCdTime().keySet()){
data.setCD(key,-1L);
amount++;
}
}
Bukkit.broadcastMessage("§c[系统]§a本次总计清理负面效果: §e"+amount+"");
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
}
if(rawSlot == 9){
if(gameManager.getBackPointType() == BackPointType.初始){
gameManager.setBackPointType(BackPointType.中间);
}else if(gameManager.getBackPointType() == BackPointType.中间){
gameManager.setBackPointType(BackPointType.尽头);
}else if(gameManager.getBackPointType() == BackPointType.尽头){
gameManager.setBackPointType(BackPointType.初始);
}
Bukkit.broadcastMessage("§c[系统]§a当前传送返回点为: §e"+gameManager.getBackPointType().name());
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
GameEditGui.OpenGui(zhubo);
}
if(rawSlot == 11){
if(e.getClick() == ClickType.LEFT){
int nowTime = gameManager.getGoalCountdown()+1;
if(nowTime >= 20){
nowTime = 20;
}
gameManager.setGoalCountdown(nowTime);
} else if(e.getClick() == ClickType.RIGHT){
int nowTime = gameManager.getGoalCountdown()-1;
if(nowTime <= 5){
nowTime = 5;
}
gameManager.setGoalCountdown(nowTime);
}
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
GameEditGui.OpenGui(zhubo);
}
if(rawSlot == 13){
zhubo.closeInventory();
zhubo.getInventory().clear();// 清理背包物品
game.initPlayerBackpack(zhubo);
zhubo.playSound(zhubo.getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND,1,1);
}
if(rawSlot == 15){
zhubo.closeInventory();
World world = zhubo.getWorld();
int amount = 0;
for (Entity entity : world.getEntities()) {
if(!(entity instanceof Player)){
entity.remove();
amount++;
}
}
Bukkit.broadcastMessage("§c[系统]§a本次总计清理: §e"+amount+"个生物");
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
}
if(rawSlot == 26){
zhubo.closeInventory();
if(e.getClick() == ClickType.LEFT){
// 重启游戏 重置矿区
FarmingWar.getGame().effect_setComplete(0); // 重置玩家当前已完成次数
game.reset();
} else if(e.getClick() == ClickType.RIGHT){
// 关闭服务器
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"stop");
}
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
}
if(rawSlot >= 18 && rawSlot < 24){
zhubo.closeInventory();
NBTItem nbti = new NBTItem(item);
int gameGoal = nbti.getInteger("gameGoal");
FarmingWar.getGameManager().setGameGoal(gameGoal);
Bukkit.broadcastMessage("§c[系统]§a今日挑战已设置为: §e"+gameGoal+"");
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
}
}
}
public static void OpenGui(Player p){
Inventory inv = Bukkit.createInventory(null,27,invTitle);
// 设置挑战次数
inv.setItem(18,CompleteAmount(Material.WHITE_WOOL,5));
inv.setItem(19,CompleteAmount(Material.LIGHT_GRAY_WOOL,10));
inv.setItem(20,CompleteAmount(Material.PINK_WOOL,15));
inv.setItem(21,CompleteAmount(Material.YELLOW_WOOL,20));
inv.setItem(22,CompleteAmount(Material.LIGHT_BLUE_WOOL,30));
inv.setItem(23,CompleteAmount(Material.RED_WOOL,50));
inv.setItem(0,BossBar_1());
inv.setItem(2,BossBar_2());
inv.setItem(4,SetGameTime());
inv.setItem(9,transferPointSetting());
inv.setItem(11,SetCountdown());
inv.setItem(13,equipThePlayer());
inv.setItem(15,Scavenger());
inv.setItem(8,Rest_Effect());
inv.setItem(26,Rest_Server());
p.openInventory(inv);
}
public static ItemStack CompleteAmount(Material material,int amount){
ItemStack item = new ItemStack(material);
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e挑战目标: §a"+amount+"");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
GameManager gameManager = FarmingWar.getGameManager();
if(gameManager.getGameGoal() == amount) {
lore.add("§b★ §c当前已经是目标"+amount+"");
item.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE,1);
} else {
lore.add("§b★ §6左键点击 §7设置目标");
}
meta.setLore(lore);
item.setItemMeta(meta);
NBTItem nbti = new NBTItem(item);
nbti.setInteger("gameGoal", amount);
item = nbti.getItem();
return item;
}
public static ItemStack transferPointSetting(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §eF键传送点");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
GameManager gameManager = FarmingWar.getGameManager();
lore.add("§b★ §7当前位置: §c"+gameManager.getBackPointType().name());
lore.add(" ");
lore.add("§b★ §6鼠标点击 §7切换位置");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(203);
item.setItemMeta(meta);
return item;
}
public static ItemStack equipThePlayer(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e切换背包装备");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add(" ");
lore.add("§b★ §6鼠标点击切换装备");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(206);
item.setItemMeta(meta);
return item;
}
public static ItemStack Scavenger(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e清理所有生物");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add("§c清理猪猪,熊猫,僵尸等");
lore.add(" ");
lore.add("§b★ §6鼠标点击清理");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(205);
item.setItemMeta(meta);
return item;
}
public static ItemStack SetCountdown(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e挑战完成倒计时");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
GameManager gameManager = FarmingWar.getGameManager();
lore.add("§b★ §7当前秒数: §c"+gameManager.getGoalCountdown()+"");
lore.add(" ");
lore.add("§b★ §6左键+1秒 §7|| §6右键-1秒");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(204);
item.setItemMeta(meta);
return item;
}
public static ItemStack Rest_Server(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e重启游戏");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add("§c重启后修改参数将生效");
lore.add(" ");
lore.add("§b★ §6左键 §7重置场地和数据");
lore.add("§b★ §6右键 §7重置服务端");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(202);
item.setItemMeta(meta);
return item;
}
public static ItemStack Rest_Effect(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e清理负面效果");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add("§c例如螺旋升天,关灯,大风车等");
lore.add(" ");
lore.add("§b★ §6鼠标点击清理");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(208);
item.setItemMeta(meta);
return item;
}
public static ItemStack BossBar_1(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e挑战进度血条");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add(" ");
lore.add("§b★ §6左键 §7显示");
lore.add("§b★ §6右键 §7隐藏");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(207);
item.setItemMeta(meta);
return item;
}
public static ItemStack BossBar_2(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e小麦种植进度");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
lore.add(" ");
lore.add("§b★ §6左键 §7显示");
lore.add("§b★ §6右键 §7隐藏");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(207);
item.setItemMeta(meta);
return item;
}
public static ItemStack SetGameTime(){
ItemStack item = new ItemStack(Material.SUGAR);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§d★ §e游戏时间锁定");
List<String> lore = new ArrayList<>();
lore.add("§8By.AuroraPixel");
GameManager gameManager = FarmingWar.getGameManager();
lore.add("§b★ §7当前秒数: §c"+gameManager.getGameTime()+"");
lore.add(" ");
lore.add("§b★ §6左键+500刻 §7|| §6右键-500刻");
meta.setLore(lore);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.setCustomModelData(209);
item.setItemMeta(meta);
return item;
}
}

View File

@ -1,5 +1,6 @@
package com.yaohun.farmingwar.data; package com.yaohun.farmingwar.data;
import com.yaohun.farmingwar.FarmingWar;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import tools.GameUtil; import tools.GameUtil;
@ -50,10 +51,10 @@ public class GiftData {
public void OutCompleEvent(int amount) { public void OutCompleEvent(int amount) {
int new_amount = this.amount * amount; int new_amount = this.amount * amount;
if(comple_type.equalsIgnoreCase("take")){ if(comple_type.equalsIgnoreCase("take")){
// ColorblindWar.getGame().effect_takeComplete(new_amount); FarmingWar.getGame().effect_takeComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §c-"+new_amount); Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §c-"+new_amount);
} else if(comple_type.equalsIgnoreCase("add")){ } else if(comple_type.equalsIgnoreCase("add")){
// ColorblindWar.getGame().effect_addComplete(new_amount); FarmingWar.getGame().effect_addComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §b+"+new_amount); Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §b+"+new_amount);
} }
} }

View File

@ -4,6 +4,7 @@ import com.yaohun.farmingwar.FarmingWar;
import com.yaohun.farmingwar.game.Game; import com.yaohun.farmingwar.game.Game;
import com.yaohun.farmingwar.game.GameSite; import com.yaohun.farmingwar.game.GameSite;
import com.yaohun.farmingwar.game.Region; import com.yaohun.farmingwar.game.Region;
import com.yaohun.gameranking.api.RankingAPI;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -119,11 +120,9 @@ public class SummonTheSheep {
} else { } else {
block.setType(Material.AIR); block.setType(Material.AIR);
} }
// 增加积分Main.configYml.addUser_Wheat(userName, 1); //RankingAPI.addUserValue(userName,"清理小麦",1);
block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1); block.getWorld().spawnParticle(Particle.VILLAGER_ANGRY, block.getLocation().add(0.5, 0.5, 0.5), 2, 0.5, 0.5, 0.5, 0.1);
} }
} else {
block.getRelative(0,-1,0).setType(Material.FARMLAND);
} }
} }
} }

View File

@ -1,8 +1,15 @@
package com.yaohun.farmingwar.game; package com.yaohun.farmingwar.game;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.yaohun.farmingwar.FarmingWar; import com.yaohun.farmingwar.FarmingWar;
import com.yaohun.farmingwar.data.LikeData; import com.yaohun.farmingwar.data.LikeData;
import com.yaohun.farmingwar.manager.GameManager;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle; import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar; import org.bukkit.boss.BossBar;
@ -10,6 +17,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -38,13 +46,14 @@ public class Game {
private int completeGoal; private int completeGoal;
private List<BukkitTask> tasks = new ArrayList<>(); private List<BukkitTask> tasks = new ArrayList<>();
private List<Entity> entities = new ArrayList<>(); private List<Entity> entities = new ArrayList<>();
public Game(){ public Game(GameManager manager){
this.completeGoal = 15;
this.world = Bukkit.getWorld("world"); this.world = Bukkit.getWorld("world");
this.region = new Region(world,new Point(-224,73,246),new Point(-204,73,266)); this.region = new Region(world,new Point(-224,73,246),new Point(-204,73,266));
bossBar1 = Bukkit.createBossBar("今日挑战进度", BarColor.WHITE, BarStyle.SEGMENTED_10); bossBar1 = Bukkit.createBossBar("今日挑战进度", BarColor.WHITE, BarStyle.SEGMENTED_10);
bossBar2 = Bukkit.createBossBar("补种进度", BarColor.GREEN, BarStyle.SEGMENTED_20); bossBar2 = Bukkit.createBossBar("补种进度", BarColor.GREEN, BarStyle.SEGMENTED_20);
bossBar3 = Bukkit.createBossBar("点赞累积数量", BarColor.WHITE, BarStyle.SEGMENTED_10); bossBar3 = Bukkit.createBossBar("点赞累积数量", BarColor.WHITE, BarStyle.SEGMENTED_10);
this.completeGoal = manager.getGameGoal();
this.countdownTime = manager.getGoalCountdown();
} }
private void updateCompleteGoalBossBar() { private void updateCompleteGoalBossBar() {
@ -106,11 +115,36 @@ public class Game {
} }
}.runTaskTimer(FarmingWar.inst(), 0L, 10L)); }.runTaskTimer(FarmingWar.inst(), 0L, 10L));
} }
public void reset() {
// 删除当前游戏场地
BlockVector3 vector1 = BlockVector3.at((region.getMin().getX()-1), 72, (region.getMin().getZ()-1));
BlockVector3 vector2 = BlockVector3.at((region.getMax().getX()+1), 74, (region.getMax().getZ()+1));
CuboidRegion cuboidRegion = new CuboidRegion(BukkitAdapter.adapt(region.getWorld()), vector1, vector2);
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(region.getWorld()))) {
editSession.setBlocks((com.sk89q.worldedit.regions.Region) cuboidRegion, BukkitAdapter.asBlockType(Material.AIR));
} catch (Exception e) {
e.printStackTrace();
}
// 重新生成游戏场地并重置游戏区域
Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> {
this.region = new Region(world,new Point(-224,73,246),new Point(-204,73,266));
},1L);
Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> {
GameUtil.loadSchematics("muban");
},5L);
Bukkit.getScheduler().runTaskLater(FarmingWar.inst(), () -> {
for (Player player : Bukkit.getOnlinePlayers()){
player.teleport(region.getHub());
}
},10L);
}
public void initPlayerData(Player player) { public void initPlayerData(Player player) {
player.setArrowCooldown(3600); player.setArrowCooldown(3600);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true); player.setAllowFlight(true);
player.teleport(region.getHub()); player.teleport(region.getHub());
bossBar1.addPlayer(player);
bossBar2.addPlayer(player);
bossBar3.addPlayer(player); bossBar3.addPlayer(player);
initPlayerBackpack(player); initPlayerBackpack(player);
} }
@ -188,7 +222,58 @@ public class Game {
tasks.remove(this); tasks.remove(this);
checking = false; checking = false;
Bukkit.broadcastMessage("§c[系统]§a挑战成功! §b游戏进度+1"); Bukkit.broadcastMessage("§c[系统]§a挑战成功! §b游戏进度+1");
GameUtil.sendAllTitle("§6§l收获成功","§f恭喜你完成挑战!",10,50,20);
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
// 遍历玩家周围20x20x20的所有方块
// 获取玩家位置中心点的坐标
Location loc = player.getLocation();
int centerX = loc.getBlockX();
int centerY = loc.getBlockY();
int centerZ = loc.getBlockZ();
for (int x = centerX - 10; x <= centerX + 10; x++) {
for (int y = centerY - 10; y <= centerY + 10; y++) {
for (int z = centerZ - 10; z <= centerZ + 10; z++) {
// 获取方块
Block block = player.getWorld().getBlockAt(x, y, z);
// 示例操作输出方块的类型
if (block.getType() != Material.AIR && region.isInRegion(block.getLocation())) {
block.breakNaturally();
}
}
}
}
// 获取玩家周围20x20x20区域内的所有实体
List<Entity> nearbyEntities = player.getWorld().getEntities();
for (Entity entity : nearbyEntities) {
if (entity instanceof Item) { // 检查是否为 Item 实体
Location itemLocation = entity.getLocation();
// 判断实体是否在20x20x20范围内
if (Math.abs(itemLocation.getX() - loc.getX()) <= 15 &&
Math.abs(itemLocation.getY() - loc.getY()) <= 15 &&
Math.abs(itemLocation.getZ() - loc.getZ()) <= 15) {
entity.setGlowing(true);
BukkitTask task = new BukkitRunnable() {
private int i = 0;
@Override
public void run() {
if(entity.isDead() || i >= 50){
if(!entity.isDead()){
entity.remove();
}
cancel();
return;
}
// 获取玩家当前位置和物品当前位置的方向向量
Vector direction = loc.toVector().subtract(itemLocation.toVector()).normalize();
// 设置物品实体的速度让它朝玩家移动
entity.setVelocity(direction.multiply(0.2)); // 调整速度大小
i++;
}
}.runTaskTimer(FarmingWar.inst(),0,2L);
addTasks(task);
}
}
}
player.playSound(player.getLocation(), "duolaameng", 1.0F, 1.0F); player.playSound(player.getLocation(), "duolaameng", 1.0F, 1.0F);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.1f); player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.1f);
} }
@ -250,6 +335,31 @@ public class Game {
}.runTaskLater( FarmingWar.inst(), 5L ); }.runTaskLater( FarmingWar.inst(), 5L );
} }
public void effect_setComplete(int amount){
completeAmount = amount;
}
public void effect_addComplete(int amount){
effect_setComplete(completeAmount + amount);
}
public void effect_takeComplete(int amount){
effect_setComplete(completeAmount - amount);
}
public BossBar getBossBar1() {
return bossBar1;
}
public BossBar getBossBar2() {
return bossBar2;
}
public void removeBossBar(Player player, BossBar bossBar) {
bossBar.removePlayer(player);
}
public void addBossBar(Player player,BossBar bossBar) {
bossBar.addPlayer(player);
}
public void createRegion(String regionKey, Region region) { public void createRegion(String regionKey, Region region) {
FileConfiguration config = FarmingWar.inst().getConfig(); FileConfiguration config = FarmingWar.inst().getConfig();
ConfigurationSection section = config.createSection(regionKey); ConfigurationSection section = config.createSection(regionKey);

View File

@ -1,5 +1,7 @@
package com.yaohun.farmingwar.game; package com.yaohun.farmingwar.game;
import com.yaohun.farmingwar.FarmingWar;
import com.yaohun.farmingwar.util.BackPointType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -18,13 +20,21 @@ public class Region {
} }
public Location getHub(){ public Location getHub(){
double x = (max.getX() - 2);
double z = (min.getZ() + max.getZ()) / 2; double z = (min.getZ() + max.getZ()) / 2;
double y = min.getY(); double y = min.getY();
if(max.getY() > y){ if(max.getY() > y){
y = max.getY(); y = max.getY();
} }
return new Location(world,x,(y+5 ),z,90,0); BackPointType backPointType = FarmingWar.getGameManager().getBackPointType();
if(backPointType == BackPointType.初始){
double x = (min.getX() + 1);
return new Location(world,x,(y+5),z,-90,45);
}else if(backPointType == BackPointType.尽头){
double x = (max.getX() - 1);
return new Location(world,x,(y+5),z,90,45);
}
double x = (min.getX() + max.getX()) / 2;
return new Location(world,x,(y+5),z,-90,90);
} }
public World getWorld() { public World getWorld() {

View File

@ -16,7 +16,10 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import tools.StackUtil; import tools.StackUtil;
@ -40,6 +43,17 @@ public class GameListener implements Listener {
} }
} }
/*主播按下F后将获得速度II的效果和急迫效果*/
@EventHandler
public void onSwap(PlayerSwapHandItemsEvent e) {
Player p = e.getPlayer();
e.setCancelled(true);
if (!p.isSneaking()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 60 * 30, 1,false,false));
p.teleport(game.getRegion().getHub());
}
}
@EventHandler @EventHandler
public void onDamageByEntity(EntityDamageByEntityEvent e){ public void onDamageByEntity(EntityDamageByEntityEvent e){
Entity entity = e.getEntity(); Entity entity = e.getEntity();

View File

@ -3,24 +3,34 @@ package com.yaohun.farmingwar.manager;
import com.io.yutian.mclive.event.ZhuboAPI; import com.io.yutian.mclive.event.ZhuboAPI;
import com.yaohun.farmingwar.data.GiftData; import com.yaohun.farmingwar.data.GiftData;
import com.yaohun.farmingwar.data.LikeData; import com.yaohun.farmingwar.data.LikeData;
import com.yaohun.farmingwar.util.BackPointType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class GameManager { public class GameManager {
private static boolean isRandomBox; private File manageFile;
private FileConfiguration manageConfig;
private int gameGoal;
private long gameTime;
private BackPointType backPointType;
private int goalCountdown;
private HashMap<String, LikeData> likeDataMap = new HashMap<>(); private HashMap<String, LikeData> likeDataMap = new HashMap<>();
private HashMap<String, GiftData> giftDataMap = new HashMap<>(); private HashMap<String, GiftData> giftDataMap = new HashMap<>();
private static boolean isRandomBox;
public GameManager(){ public GameManager(){
Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 工具注册:"); Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 工具注册:");
loadRandomBoxPlugin(); loadRandomBoxPlugin();
Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 游戏设置:");
loadSettingsData();
Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 事件注册:"); Bukkit.getConsoleSender().sendMessage("[日志 - 保卫小麦] 事件注册:");
File file = new File("./plugins/游戏设置","礼物设置.yml"); File file = new File("./plugins/游戏设置","礼物设置.yml");
FileConfiguration gift_yml = YamlConfiguration.loadConfiguration(file); FileConfiguration gift_yml = YamlConfiguration.loadConfiguration(file);
@ -43,6 +53,31 @@ public class GameManager {
} }
} }
public void loadSettingsData(){
manageFile = new File("./plugins/游戏设置","游戏设置.yml");
manageConfig = YamlConfiguration.loadConfiguration(manageFile);
backPointType = BackPointType.valueOf(manageConfig.getString("返回传送点","初始"));
Bukkit.getConsoleSender().sendMessage("返回传送点: "+backPointType.name());
gameGoal = manageConfig.getInt("挑战目标",20);
Bukkit.getConsoleSender().sendMessage("挑战完成次数: "+gameGoal+"");
goalCountdown = manageConfig.getInt("完成倒计时",11);
Bukkit.getConsoleSender().sendMessage("完成挑战倒计时: "+goalCountdown+"");
gameTime = manageConfig.getLong("游戏时间定格",5500L);
Bukkit.getConsoleSender().sendMessage("游戏时间定格: "+gameTime+"");
}
public void saveGameSettings(){
manageConfig.set("挑战目标",gameGoal);
manageConfig.set("返回传送点",backPointType.name());
manageConfig.set("完成倒计时",goalCountdown);
manageConfig.set("游戏时间定格",gameTime);
try {
manageConfig.save(manageFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void loadRandomBoxPlugin() { public void loadRandomBoxPlugin() {
if(Bukkit.getPluginManager().getPlugin("RandomBox") != null){ if(Bukkit.getPluginManager().getPlugin("RandomBox") != null){
isRandomBox = true; isRandomBox = true;
@ -53,6 +88,37 @@ public class GameManager {
} }
} }
public long getGameTime() {
return gameTime;
}
public void setGameTime(long gameTime) {
this.gameTime = gameTime;
}
public int getGameGoal() {
return gameGoal;
}
public void setGameGoal(int gameGoal) {
this.gameGoal = gameGoal;
}
public int getGoalCountdown() {
return goalCountdown;
}
public void setGoalCountdown(int goalCountdown) {
this.goalCountdown = goalCountdown;
}
public BackPointType getBackPointType() {
return backPointType;
}
public void setBackPointType(BackPointType backPointType) {
this.backPointType = backPointType;
}
public static boolean isIsRandomBox() { public static boolean isIsRandomBox() {
return isRandomBox; return isRandomBox;

View File

@ -0,0 +1,5 @@
package com.yaohun.farmingwar.util;
public enum BackPointType {
初始,中间,尽头
}

View File

@ -54,5 +54,13 @@ public class CDTimeAPI {
public long getCD(String key) { public long getCD(String key) {
return this.cdTime.getOrDefault(key,-1L); return this.cdTime.getOrDefault(key,-1L);
} }
public HashMap<String, Long> getCdTime() {
return cdTime;
}
}
public static HashSet<CDData> getCdData() {
return cdData;
} }
} }

View File

@ -46,7 +46,6 @@ public class StackUtil {
} }
public static ItemStack quickPotion(){ public static ItemStack quickPotion(){
ItemStack item = new ItemStack(Material.SPLASH_POTION); ItemStack item = new ItemStack(Material.SPLASH_POTION);
item.setAmount(6);
PotionMeta meta = (PotionMeta) item.getItemMeta(); PotionMeta meta = (PotionMeta) item.getItemMeta();
meta.setBasePotionData(new PotionData(PotionType.SPEED,false,false)); meta.setBasePotionData(new PotionData(PotionType.SPEED,false,false));
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);

View File

@ -4,3 +4,5 @@ version: 1.0
api-version: '1.18' api-version: '1.18'
commands: commands:
game: game:
gameedit:
livegift: