测试版2.0

This commit is contained in:
yaohunya 2024-10-21 07:49:16 +08:00
commit dd95bcb686
35 changed files with 2771 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.idea/

View File

@ -0,0 +1,127 @@
package com.yutian.minerwar;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.BlockVector3;
import com.yutian.minerwar.data.RepairGiftGui;
import com.yutian.minerwar.game.Game;
import com.yutian.minerwar.game.Point;
import com.yutian.minerwar.game.Region;
import com.yutian.minerwar.listener.*;
import com.yutian.minerwar.liveevent.GiftEventHandler;
import com.yutian.minerwar.liveevent.GiftListener;
import com.yutian.minerwar.liveevent.KeyInputListener;
import com.yutian.minerwar.liveevent.LikeListener;
import com.yutian.minerwar.manager.GameManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import tools.GameUtil;
import tools.RandomUtil;
import java.util.ArrayList;
import java.util.List;
public class MinerWar extends JavaPlugin {
private static MinerWar instance;
private static Game game;
private static GameManager gameManager;
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
gameManager = new GameManager();
game = new Game(gameManager);
Bukkit.getPluginManager().registerEvents(new GiftListener(), this);
Bukkit.getPluginManager().registerEvents(new LikeListener(), this);
Bukkit.getPluginManager().registerEvents(new JoinListener(), this);
Bukkit.getPluginManager().registerEvents(new GamePotect(), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getPluginManager().registerEvents(new GameListener(), this);
Bukkit.getPluginManager().registerEvents(new GameEffect(), this);
Bukkit.getPluginManager().registerEvents(new KeepEntitiesOnDeath(), this);
Bukkit.getPluginManager().registerEvents(new FoodAndMedicineListener(), this);
Bukkit.getPluginManager().registerEvents(new KeyInputListener(), this);
Bukkit.getPluginManager().registerEvents(new RepairGiftGui(), this);
}
@Override
public void onDisable() {
gameManager.saveGameSettings();
game.stop();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String Command, String[] args) {
if (Command.equalsIgnoreCase("livegift")) {
// RepairGiftGui.OpenGui((Player) sender);
return true;
}
if (Command.equalsIgnoreCase("gameedit")) {
// GameEditGui.OpenGui((Player) sender);
return true;
}
if (Command.equalsIgnoreCase("game")) {
if (args.length == 0) {
sender.sendMessage("/game start - 开始游戏");
sender.sendMessage("/game keyd - 按键调试");
return true;
}
if(args.length == 1 && args[0].equalsIgnoreCase("keyd")){
if(gameManager.isKeyInputd()){
gameManager.setKeyInputd(false);
sender.sendMessage("按键调试: 已关闭");
}else {
gameManager.setKeyInputd(true);
sender.sendMessage("按键调试: 已开启");
}
return true;
}
if (args[0].equalsIgnoreCase("region")) {
String regionKey = args[1];
Player player = (Player) sender;
Actor actor = BukkitAdapter.adapt(player);
LocalSession localSession = actor.getSession();
com.sk89q.worldedit.regions.Region region = localSession.getSelection(BukkitAdapter.adapt(player.getWorld()));
if (region == null) {
player.sendMessage("请先选中一个区域");
return true;
}
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
Point minPoint = new Point(min.getBlockX(), min.getBlockY(), min.getBlockZ());
Point maxPoint = new Point(max.getBlockX(), max.getBlockY(), max.getBlockZ());
Region region1 = new Region(player.getWorld(), minPoint, maxPoint);
game.createRegion(regionKey, region1);
player.sendMessage("区域创建成功.");
}
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 Plugin inst() {return instance;}
public static Game getGame() {return game;}
public static GameManager getGameManager() {return gameManager;}
}

View File

@ -0,0 +1,13 @@
package com.yutian.minerwar.api;
import com.yutian.minerwar.util.GiftUtil;
import org.bukkit.entity.Player;
public class DzMinerWarAPI {
public static void sendSimulatedGiftEffect(Player player, String userName, String giftName, int amount){
GiftUtil.simulatedGiftEffect(player,userName,giftName,amount);
}
public static void sendSimulateEventEffect(Player player,String userName,String eventName,int amount){
GiftUtil.simulateEventEffect(player,userName,eventName,amount);
}
}

View File

@ -0,0 +1,66 @@
package com.yutian.minerwar.data;
import com.yutian.minerwar.MinerWar;
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")){
MinerWar.getGame().effect_takeComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §c-"+new_amount);
} else if(comple_type.equalsIgnoreCase("add")){
MinerWar.getGame().effect_addComplete(new_amount);
Bukkit.broadcastMessage("§c[系统]§a今日挑战进度: §b+"+new_amount);
}
}
public void OutPlaySoundsEvent() {
if(!sounds.equalsIgnoreCase("NULL")) {
GameUtil.sendAllSound(sounds);
}
}
}

View File

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

View File

@ -0,0 +1,278 @@
package com.yutian.minerwar.data;
import com.io.yutian.mclive.event.ZhuboAPI;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.liveevent.GiftEventHandler;
import com.yutian.minerwar.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 = MinerWar.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(MinerWar.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(MinerWar.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 = MinerWar.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(MinerWar.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<>();
if(ZhuboAPI.getRoomLiveName().equalsIgnoreCase("KuaiShou")) {
hashMap.put("棒棒糖",stackGift("棒棒糖", 101));
hashMap.put("比心",stackGift("比心", 102));
hashMap.put("粉丝团灯牌",stackGift("粉丝团灯牌", 103));
hashMap.put("集结票",stackGift("集结票", 104));
hashMap.put("浪漫风铃",stackGift("浪漫风铃", 105));
hashMap.put("玫瑰",stackGift("玫瑰", 106));
hashMap.put("玫瑰花园",stackGift("玫瑰花园", 107));
hashMap.put("魔法箱子",stackGift("魔法箱子", 108));
hashMap.put("摸摸头",stackGift("摸摸头", 109));
hashMap.put("陪伴你",stackGift("陪伴你", 110));
hashMap.put("啤酒",stackGift("啤酒", 111));
hashMap.put("人气卡",stackGift("人气卡", 112));
hashMap.put("人气票",stackGift("人气票", 113));
hashMap.put("送你花环",stackGift("送你花环", 114));
hashMap.put("童话日记",stackGift("童话日记", 115));
hashMap.put("小白菜",stackGift("小白菜", 116));
hashMap.put("钻戒",stackGift("钻戒", 117));
hashMap.put("荧光棒",stackGift("荧光棒", 118));
hashMap.put("小可爱",stackGift("小可爱", 119));
} else {
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 = MinerWar.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 (MinerWar.getGameManager().getGiftData(name) != null) {
GiftData giftData = MinerWar.getGameManager().getGiftData(name);
lore.add("§7触发效果: §a" + giftData.getEvent() + " " + giftData.getComple_Show());
} else {
lore.add("§7触发效果: §c无");
}
lore.add(" ");
lore.add("§b§l★ §6左键点击 §7召唤1次");
lore.add("§b§l★ §6右键点击 §7召唤10次");
lore.add("§b§l★ §6SHIFT+点击 §7自定义数量");
meta.setLore(lore);
if (model_id >= 1){
meta.setCustomModelData(model_id);
}else{
item.setType(Material.DIAMOND);
}
item.setItemMeta(meta);
NBTItem nbti = new NBTItem(item);
nbti.setString("giftName",name);
item = nbti.getItem();
return item;
}
}

View File

@ -0,0 +1,70 @@
package com.yutian.minerwar.effects;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import tools.CDTimeAPI;
import java.util.UUID;
public class PotionBlindness {
public static void apply(Game game, Player zhubo, int seconds){
// 检测游戏是否启动
if(!game.isStarted()){return;}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "turnOffTheLight";
startTimepieceEvent(game,zhubo,timepieceKey);
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * seconds);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * seconds);
}
double effectTime = (CDTimeAPI.getCD(uuid,timepieceKey) / 1000.0) * 20;
// 获取现有致盲效果
PotionEffect existingEffect = zhubo.getPotionEffect(PotionEffectType.BLINDNESS);
if (existingEffect != null) {
zhubo.removePotionEffect(PotionEffectType.BLINDNESS);
}
PotionEffect newEffect = new PotionEffect(PotionEffectType.BLINDNESS, (int) effectTime, 1); // 持续6秒6 * 20ticks
zhubo.addPotionEffect(newEffect);
}
public static void startTimepieceEvent(Game game,Player zhubo,String timepieceKey) {
if (CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) {
return;
}
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
if (!CDTimeAPI.isCD(zhubo.getUniqueId(), timepieceKey)) {
zhubo.removePotionEffect(PotionEffectType.BLINDNESS);
zhubo.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 5, 1));
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_PLAYER_LEVELUP,1,1);
cancel();
return;
}
PotionEffect existingEffect = zhubo.getPotionEffect(PotionEffectType.BLINDNESS);
if (existingEffect != null) {
// 如果已经有致盲效果则延长其持续时间
int newDuration = existingEffect.getDuration();
if(newDuration <= 20){
zhubo.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
}
} else {
zhubo.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
}
}
}.runTaskTimer(MinerWar.inst(), 0L, 10L);
game.addTasks(task);
}
}

View File

@ -0,0 +1,70 @@
package com.yutian.minerwar.effects;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import org.bukkit.Location;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import tools.CDTimeAPI;
import tools.RandomUtil;
import java.util.Random;
import java.util.UUID;
public class ShoutArrow {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {return;}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "SummonArrowEffect";
startTimepieceEvent(game,zhubo,timepieceKey);
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (250L * amount);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,250L * amount);
}
}
public static void startTimepieceEvent(Game game,Player zhubo,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;
}
spawnArrowAroundPlayer(zhubo,5);
}
}.runTaskTimer(MinerWar.inst(), 0L, 5L);
game.addTasks(task);
}
public static void spawnArrowAroundPlayer(Player player, double radius) {
Random random = new Random();
Location playerLocation = player.getLocation();
// 生成一个随机的圆周位置
double angle = 2 * Math.PI * random.nextDouble(); // 随机角度
double x = radius * Math.cos(angle); // 随机 x
double z = radius * Math.sin(angle); // 随机 z
// 获取随机位置
Location randomLocation = playerLocation.clone().add(x, RandomUtil.getRandomInt(0,2), z);
// 创建箭矢
Arrow arrow = (Arrow) player.getWorld().spawnEntity(randomLocation, EntityType.ARROW);
// 计算箭矢的朝向
Vector direction = playerLocation.toVector().subtract(randomLocation.toVector()).normalize();
// 设置箭矢的方向
arrow.setVelocity(direction.multiply(3)); // 2 是箭矢的速度可以调整
arrow.setPersistent(true); // 设置箭矢的持久性
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED); // 禁止拾取箭矢
}
}

View File

@ -0,0 +1,67 @@
package com.yutian.minerwar.effects;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Bee;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import tools.RandomUtil;
public class SummonTheBee {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {return;}
if(amount >= 200){
// 获取掉落次数
int forA = 10 + (amount / 50);
// 获取每次掉落数量
int forB = (int) (amount / forA * 0.7);
for (int i = 0; i < forA;i++){
Bukkit.getScheduler().runTaskLater(MinerWar.inst(), () -> {
for (int a = 0; a < forB;a++) {
spawnMobs(zhubo,userName);
}
zhubo.playSound(zhubo.getLocation(), "huh", 1.0F, 1.0F);
},(long) i*5);
}
}else if(amount >= 120){
for (int i = 0; i < 20;i++){
Bukkit.getScheduler().runTaskLater(MinerWar.inst(), () -> {
for (int ai = 0; ai < 6;ai++) {
spawnMobs(zhubo,userName);
}
zhubo.playSound(zhubo.getLocation(), "huh", 1.0F, 1.0F);
},(long) i*5);
}
}else if(amount >= 30){
for (int i = 0; i < 10;i++){
Bukkit.getScheduler().runTaskLater(MinerWar.inst(), () -> {
for (int ai = 0; ai < 3;ai++) {
spawnMobs(zhubo,userName);
}
zhubo.playSound(zhubo.getLocation(), "huh", 1.0F, 1.0F);
},(long) i*5);
}
}else {
for (int i = 0; i < amount; i++) {
spawnMobs(zhubo,userName);
}
zhubo.playSound(zhubo.getLocation(), "huh", 1.0F, 1.0F);
}
}
public static void spawnMobs(Player zhubo,String userName){
Location location = zhubo.getLocation().add(0,3,0);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 2, 1, 1, 1, 0.085);
Bee entity = (Bee) location.getWorld().spawnEntity(location, EntityType.BEE);
entity.setTarget(zhubo);
entity.setHealth(1);
entity.setCustomName("§c" + userName);
entity.setCustomNameVisible(true);
Vector vector = new Vector(RandomUtil.getRandomDouble(-1,1,1), RandomUtil.getRandomDouble(-1,1,1),RandomUtil.getRandomDouble(-1,1,1));
entity.setVelocity(vector);
}
}

View File

@ -0,0 +1,58 @@
package com.yutian.minerwar.effects;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.EvokerFangs;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import tools.CDTimeAPI;
import java.util.UUID;
public class SummonTheEvokerFang {
public static void apply(Game game, Player zhubo, String userName, int amount) {
if (!game.isStarted()) {return;}
// 获取主播的uuid
UUID uuid = zhubo.getUniqueId();
// 计时器key
String timepieceKey = "SummonEvokerFangsEffect";
startTimepieceEvent(game,zhubo,userName,timepieceKey);
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (250L * amount);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,250L * 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(zhubo,userName);
}
}.runTaskTimer(MinerWar.inst(), 0L, 5L);
game.addTasks(task);
}
public static void spawnMobs(Player zhubo,String userName){
Location location = zhubo.getLocation().clone();
location.getWorld().spawnParticle(Particle.LAVA, location, 3, 1, 1, 1, 0.085);
EvokerFangs entity = (EvokerFangs) location.getWorld().spawnEntity(location, EntityType.EVOKER_FANGS);
entity.setCustomName("§c" + userName);
entity.setCustomNameVisible(true);
}
}

View File

@ -0,0 +1,281 @@
package com.yutian.minerwar.game;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.math.BlockVector3;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.manager.GameManager;
import com.yutian.minerwar.util.MerchantRecipeUtil;
import org.bukkit.*;
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.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import tools.BossBarUtil;
import tools.RandomUtil;
import tools.StackUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Game {
private World world;
private BossBar bossBar1;
private BossBar bossBar2;
private boolean started = false;
private Villager villagerShop;
private Location villagerPoint;
private Region gameRegion;
private int completeAmount;
private int completeGoal;
private int excavateAmount;
private int excavateGoal;
private List<BukkitTask> tasks = new ArrayList<>();
protected List<MerchantRecipe> recipes = new ArrayList<>();
private final GameManager manager;
public Game(GameManager gameManager) {
manager = gameManager;
world = Bukkit.getWorld("world");
if (world != null) {
world.setAutoSave(false);
world.setGameRule(GameRule.KEEP_INVENTORY,true);
world.setGameRule(GameRule.MOB_GRIEFING,false);
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE,false);
world.setGameRule(GameRule.DO_WEATHER_CYCLE,false);
world.setDifficulty(Difficulty.NORMAL);
world.setTime(2000L);
gameRegion = new Region(world,new Point(-150,60,-200),new Point(150,120,100));
initVillagerShop();
initGoldOreGenerate();
}
bossBar1 = Bukkit.createBossBar("今日挑战进度", BarColor.WHITE, BarStyle.SEGMENTED_10);
bossBar2 = Bukkit.createBossBar("黄金采集进度", BarColor.GREEN, BarStyle.SEGMENTED_20);
this.completeGoal = manager.getGameGoal();
this.excavateGoal = manager.getGoldOreGoal();
tasks.add(Bukkit.getScheduler().runTaskTimer(MinerWar.inst(),this::tickFood,0,30*20L));
}
private void updateCompleteGoalBossBar() {
double d = (double) completeAmount / (double) completeGoal;
String bossTitle = "§6今日挑战进度: §f"+completeAmount+"/"+completeGoal;
bossBar1.setTitle(bossTitle);
BossBarUtil.setBarColor(bossBar1,d);
BossBarUtil.setBarProgress(bossBar1,d);
}
private void updateCompleteGoldGoalBossBar() {
int cNow = excavateAmount;
int cMax = excavateGoal;
double d = (double) cNow / (double) cMax;
String d2 = String.format("%.2f",d * 100);
String bossTitle = "§6黄金矿工采集进度: §f"+cNow+"/"+cMax+" §b("+d2+"%)";
bossBar2.setTitle(bossTitle);
BossBarUtil.setBarColor(bossBar2,d);
BossBarUtil.setBarProgress(bossBar2,d);
}
public void start() {
if (started) {
return;
}
this.started = true;
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
villagerShop.teleport(villagerPoint);
updateCompleteGoldGoalBossBar();
updateCompleteGoalBossBar();
}
}.runTaskTimer(MinerWar.inst(),0L,10L);
tasks.add(task);
}
public void stop(){
villagerShop.remove();
for (Player player1 : Bukkit.getOnlinePlayers()){
player1.getInventory().clear();
}
}
public boolean isStarted() {
return started;
}
public void initPlayerData(Player player) {
player.setArrowCooldown(3600);
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true);
bossBar1.addPlayer(player);
bossBar2.addPlayer(player);
initPlayerBackpack(player);
}
public void initPlayerBackpack(Player player){
Inventory inv = player.getInventory();
inv.setItem(0,StackUtil.diamondSword());
inv.setItem(1,StackUtil.ironPickaxe());
inv.setItem(2,new ItemStack(Material.WATER_BUCKET,1));
}
public void initVillagerShop(){
Location location = new Location(world,-7,78,-76,-90,0);
world.getBlockAt(location).setType(Material.SEA_LANTERN);
villagerPoint = location.add(0.5,1,0.5);
Villager villager = (Villager) world.spawnEntity(villagerPoint, EntityType.VILLAGER);
villager.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.0D);
villager.getAttribute(Attribute.GENERIC_ARMOR).setBaseValue(99999.0);
villager.getAttribute(Attribute.GENERIC_ARMOR_TOUGHNESS).setBaseValue(99999.0);
villager.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE).setBaseValue(99999.0);
villager.setInvulnerable(true);
villager.setGravity(false);
villager.setProfession(Villager.Profession.CLERIC);
villager.setVillagerType(Villager.Type.SWAMP);
villager.setVillagerLevel(5);
villager.setRecipes(getRecipes());
villager.setCustomNameVisible(true);
villager.setCustomName("§e§l商人");
villager.setCollidable(false);
villagerShop = villager;
}
private List<MerchantRecipe> getRecipes() {
if(recipes.isEmpty()) {
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(new ItemStack(Material.COOKIE, 1), 1));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(new ItemStack(Material.BREAD, 1), 3));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(new ItemStack(Material.COOKED_BEEF, 1), 5));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(new ItemStack(Material.COOKED_CHICKEN, 1), 7));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(new ItemStack(Material.RABBIT_STEW, 1), 10));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(StackUtil.bloodBag(), 3));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(StackUtil.bigBloodBag(), 9));
recipes.add(MerchantRecipeUtil.buildMerchantRecipe(StackUtil.extraGradeBloodPack(), 15));
}
return recipes;
}
public void initGoldOreGenerate(){
Region region = gameRegion;
Bukkit.getConsoleSender().sendMessage("[日志 - 矿工战争] 游戏场地:");
// 清理这个区域中所有的非白名单方块
for (int y = 70; y <= 120; y++) {
for (int x = (int) Math.floor(region.getMin().getX()); x <= region.getMax().getX(); x++) {
for (int z = (int) Math.floor(region.getMin().getZ()); z <= region.getMax().getZ(); z++) {
if(z != -76) {
Block block = region.getWorld().getBlockAt(x, y, z);
if (!block.getType().equals(Material.AIR)) {
if (block.getType() == Material.WHITE_WOOL) {
if (RandomUtil.getRandomInt(1, 100) >= 70) {
block.setType(Material.GOLD_ORE);
} else {
block.setType(Material.COBBLESTONE);
}
}
}
}
}
}
}
}
public void tickFood() {
for (Player player1 : world.getPlayers()) {
int foodLevel = player1.getFoodLevel();
player1.setFoodLevel(Math.max(foodLevel - 1, 0));
}
}
public void createRegion(String regionKey, Region region) {
FileConfiguration config = MinerWar.inst().getConfig();
ConfigurationSection section = config.createSection(regionKey);
section.set("world", region.getWorld().getName());
Point point1 = region.getMin();
Point point2 = region.getMax();
ConfigurationSection section1 = section.createSection("min");
section1.set("x", point1.getX());
section1.set("y", point1.getY());
section1.set("z", point1.getZ());
ConfigurationSection section2 = section.createSection("max");
section2.set("x", point2.getX());
section2.set("y", point2.getY());
section2.set("z", point2.getZ());
MinerWar.inst().saveConfig();
}
public void addTasks(BukkitTask task) {
tasks.add(task);
}
public Location getVillagerPoint() {
return villagerPoint;
}
public Villager getVillagerShop() {
return villagerShop;
}
public Region getGameRegion() {
return gameRegion;
}
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 int getExcavateAmount() {
return excavateAmount;
}
public void setExcavateAmount(int excavateAmount) {
this.excavateAmount = excavateAmount;
}
public void effect_RefreshExcavateAmount(Player player){
int amount = 0;
Inventory inv = player.getInventory();
for (int i = 0;i < 36;i++){
ItemStack item = inv.getItem(i);
if(item != null && item.getType() != Material.AIR){
if(item.getType().equals(Material.RAW_GOLD)){
amount = amount + item.getAmount();
}
}
}
setExcavateAmount(amount);
}
public int getExcavateAmount(Player player){
int amount = 0;
Inventory inv = player.getInventory();
for (int i = 0;i < 36;i++){
ItemStack item = inv.getItem(i);
if(item != null && item.getType() != Material.AIR){
if(item.getType().equals(Material.RAW_GOLD)){
amount = amount + item.getAmount();
}
}
}
return amount;
}
}

View File

@ -0,0 +1,94 @@
package com.yutian.minerwar.game;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Objects;
public class Point {
private double x;
private double y;
private double z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public void setZ(double z) {
this.z = z;
}
public Point clone() {
return new Point(x, y, z);
}
public Location toLocation(World world) {
return new Location(world, x, y, z, 0, 0);
}
public static Point of(Location location) {
return new Point(location.getX(), location.getY(), location.getZ());
}
public static Point deserialize(ConfigurationSection section) {
return new Point(section.getDouble("x"), section.getDouble("y"), section.getDouble("z"));
}
public BlockVector3 toBlockVector3() {
return BlockVector3.at(x, y, z);
}
@Override
public String toString() {
return "Point{" +
"x=" + x +
", y=" + y +
", z=" + z +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
return Double.compare(point.x, x) == 0 && Double.compare(point.y, y) == 0 && Double.compare(point.z, z) == 0;
}
@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
}

View File

@ -0,0 +1,69 @@
package com.yutian.minerwar.game;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
public class Region {
private World world;
private Point min;
private Point max;
public Region(World world, Point min, Point max) {
this.world = world;
this.min = min;
this.max = max;
}
public World getWorld() {
return world;
}
public Point getMin() {
return min;
}
public Point getMax() {
return max;
}
public void setMax(Point max) {
this.max = max;
}
public void setMin(Point min) {
this.min = min;
}
public static Region deserialize(ConfigurationSection section) {
World world1 = Bukkit.getWorld(section.getString("world"));
Point point1 = Point.deserialize(section.getConfigurationSection("min"));
Point point2 = Point.deserialize(section.getConfigurationSection("max"));
return new Region(world1, point1, point2);
}
public boolean isInRegion(Location location) {
if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) {
return false;
}
return (location.getBlockX() >= this.min.getX()
&& location.getBlockX() <= this.max.getX()
&& location.getBlockY() >= this.min.getY()
&& location.getBlockY() <= this.max.getY()
&& location.getBlockZ() >= this.min.getZ()
&& location.getBlockZ() <= this.max.getZ());
}
public boolean isInRegionPlayer(Location location) {
if (!location.getWorld().getName().equalsIgnoreCase(world.getName())) {
return false;
}
return (location.getBlockX() >= this.min.getX()-1
&& location.getBlockX() <= this.max.getX()+1
&& location.getBlockZ() >= this.min.getZ()-1
&& location.getBlockZ() <= this.max.getZ()+1);
}
}

View File

@ -0,0 +1,107 @@
package com.yutian.minerwar.listener;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class FoodAndMedicineListener implements Listener {
/*
* 吃指定的食物恢复指定的饱和度
* */
@EventHandler
public void onPlayerConsume(PlayerItemConsumeEvent event) {
// 获取玩家和物品
Player player = event.getPlayer();
Material itemType = event.getItem().getType();
switch (itemType) {
case COOKIE:
setFoodAndSaturation(player, 2,Material.COOKIE); // 曲奇饼
break;
case BREAD:
setFoodAndSaturation(player, 6,Material.BREAD); // 面包
break;
case COOKED_BEEF:
setFoodAndSaturation(player, 10,Material.COOKED_BEEF); // 熟牛排
break;
case COOKED_CHICKEN:
setFoodAndSaturation(player, 14,Material.COOKED_CHICKEN); // 熟鸡肉
break;
case RABBIT_STEW:
setFoodAndSaturation(player, 20,Material.RABBIT_STEW); // 兔肉煲
break;
case POTATO:
setMedicamentAndSaturation(player,event.getItem()); // 兔肉煲
break;
default:
// 对于其他食物不做处理
break;
}
// 自定义饱食度逻辑
event.setCancelled(true);
}
// 设置饱食度和饱和度的方法
private void setFoodAndSaturation(Player player,int foodLevel,Material material) {
// 增加饱食度食物条并设置饱和度
int newFoodLevel = Math.min(player.getFoodLevel() + foodLevel, 20); // 最大饱食度为20
player.setFoodLevel(newFoodLevel);
player.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,player.getLocation().add(0,1,0),10,0.1,0.1,0.1,0.3);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_BURP,1,1);
ItemStack mainHand = player.getInventory().getItemInMainHand();
if (mainHand != null && mainHand.getType().equals(material)) {
if (mainHand.getAmount() == 1) {
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
} else {
mainHand.setAmount(mainHand.getAmount() - 1);
}
} else {
ItemStack offHand = player.getInventory().getItemInOffHand();
if (offHand != null && offHand.getType().equals(material)) {
if (offHand.getAmount() == 1) {
player.getInventory().setItemInOffHand(new ItemStack(Material.AIR));
} else {
offHand.setAmount(offHand.getAmount() - 1);
}
}
}
}
private void setMedicamentAndSaturation(Player player,ItemStack stack) {
int healLevel = 2;
ItemMeta meta = stack.getItemMeta();
assert meta != null;
if(meta.getCustomModelData() == 802){
healLevel = 6;
}else if(meta.getCustomModelData() == 803){
healLevel = 10;
}
int newHealLevel = (int) Math.min(player.getHealth() + healLevel, 20);
player.setHealth(newHealLevel);
player.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,player.getLocation().add(0,1,0),10,0.1,0.1,0.1,0.3);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_BURP,1,1);
ItemStack mainHand = player.getInventory().getItemInMainHand();
if (mainHand != null && mainHand.getType().equals(stack.getType())) {
if (mainHand.getAmount() == 1) {
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
} else {
mainHand.setAmount(mainHand.getAmount() - 1);
}
} else {
ItemStack offHand = player.getInventory().getItemInOffHand();
if (offHand != null && offHand.getType().equals(stack.getType())) {
if (offHand.getAmount() == 1) {
player.getInventory().setItemInOffHand(new ItemStack(Material.AIR));
} else {
offHand.setAmount(offHand.getAmount() - 1);
}
}
}
}
}

View File

@ -0,0 +1,80 @@
package com.yutian.minerwar.listener;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import tools.CDTimeAPI;
import tools.RandomUtil;
import java.util.UUID;
public class GameEffect implements Listener {
@EventHandler
public void onMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
UUID uuid = p.getUniqueId();
Location loc = p.getLocation();
World world = loc.getWorld();
if (CDTimeAPI.getCD(uuid, "angelicSanctuary") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "angelicSanctuary");
double seconds = (double) milliseconds / 1000;
String message = "§6天使庇护剩余时间: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "supermining") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "supermining");
double seconds = (double) milliseconds / 1000;
String message = "§6超级挖掘剩余时间: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "SummonArrowEffect") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "SummonArrowEffect");
int seconds = (int) milliseconds / 250;
String message = "§6箭头剩余未发射: §b" + seconds + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "SummonEvokerFangsEffect") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "SummonEvokerFangsEffect");
int seconds = (int) milliseconds / 250;
String message = "§6地刺剩余数量: §b" + seconds + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "bigWindill") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "bigWindill");
double seconds = (double) milliseconds / 1000;
String message = "§6大风车倒计时: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "turnOffTheLight") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "turnOffTheLight");
double seconds = (double) milliseconds / 1000;
String message = "§6致盲时刻倒计时: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "slowEffect") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "slowEffect");
double seconds = (double) milliseconds / 1000;
String message = "§6迟缓药水倒计时: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
} else if (CDTimeAPI.getCD(uuid, "speedEffect") >= 1) {
long milliseconds = CDTimeAPI.getCD(uuid, "speedEffect");
double seconds = (double) milliseconds / 1000;
String message = "§6加速药水倒计时: §b" + String.format("%.1f", seconds) + "";
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(message));
}
// 设置颜色为红色
Color color = Color.RED;
int random = RandomUtil.getRandomInt(1, 100);
if (random >= 75) {
color = Color.OLIVE;
} else if (random >= 50) {
color = Color.AQUA;
} else if (random >= 25) {
color = Color.GREEN;
}
world.spawnParticle(Particle.REDSTONE, loc.add(0, 0.2, 0), 2, 0.1, 0.1, 0.1, new Particle.DustOptions(color, 1));
}
}

View File

@ -0,0 +1,162 @@
package com.yutian.minerwar.listener;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import com.yutian.minerwar.game.Point;
import com.yutian.minerwar.game.Region;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import tools.CDTimeAPI;
import java.util.Iterator;
public class GameListener implements Listener {
/*
* 当玩家拾取粗金时增加游戏进度
* */
@EventHandler
public void onPick(PlayerPickupItemEvent e){
Player p = e.getPlayer();
if(e.getItem().getItemStack().getType().equals(Material.RAW_GOLD)){
Game game = MinerWar.getGame();
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
p.getWorld().spawnParticle(Particle.FIREWORKS_SPARK,p.getLocation().add(0,1,0),15,0.5,0.5,0.5,0.1);
new BukkitRunnable() {
@Override
public void run() {
game.effect_RefreshExcavateAmount(p); // 刷新玩家背包中的粗金
}
}.runTaskLater(MinerWar.inst(),10L);
}else {
e.setCancelled(true);
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP,1,1);
e.getItem().remove();
}
}
/*
* 当玩家破坏金矿后将在300秒后重新生成一个新的金矿石
* */
@EventHandler
public void onBreakGoldOre(BlockBreakEvent e){
// 判断破坏的方块是否是金矿
Block block = e.getBlock();
World world = block.getWorld();
if(block.getType().equals(Material.GOLD_ORE)) {
Player player = e.getPlayer();
if (CDTimeAPI.isCD(player.getUniqueId(),"supermining")) {
world.dropItem(block.getLocation().add(0,1,0),new ItemStack(Material.RAW_GOLD));
}
// 获取这个方块的坐标
Location location = block.getLocation();
// 创建计时器300秒 每5秒出现一次红石粒子
Game game = MinerWar.getGame();
BukkitTask task = new BukkitRunnable() {
private int i = 0;
// 粒子出现的坐标点
private final Location particlLoc = location.clone().add(0.5,0.5,0.5);
@Override
public void run() {
// i = 1 = 5秒
if (i >= 4) {
// 刷新矿石同时终止计时器
world.getBlockAt(location).setType(Material.GOLD_ORE);
world.spawnParticle(Particle.VILLAGER_HAPPY,particlLoc,5,0.5,0.5,0.5,0.1);
cancel();
return;
}
// 村民生气粒子效果
world.spawnParticle(Particle.VILLAGER_ANGRY,particlLoc,5,0.5,0.5,0.5,0.1);
i++;
}
}.runTaskTimer(MinerWar.inst(), 0L, 20L * 5);
game.addTasks(task);
}else if(block.getType().equals(Material.COBBLESTONE)){
// 获取这个方块的坐标
Location location = block.getLocation();
Game game = MinerWar.getGame();
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
world.getBlockAt(location).setType(Material.COBBLESTONE);
}
}.runTaskLater(MinerWar.inst(), 20L * 10);
game.addTasks(task);
}
}
@EventHandler /*主播受到伤害关闭飞行*/
public void onDamagerBee(EntityDamageByEntityEvent e) {
Game game = MinerWar.getGame();
if (game.isStarted()) {
if (e.getEntity() instanceof Player) {
if (e.getDamager() instanceof Bee) {
Bee bee = (Bee) e.getDamager();
if (bee.getTarget() != null && bee.getTarget() instanceof Player) {
((Bee) e.getDamager()).setHealth(0);
shieldBlockEvent(e.getEntity(),e,0D);
}
}
if (e.getDamager() instanceof Arrow) {
shieldBlockEvent(e.getEntity(),e,0D);
}
if (e.getDamager() instanceof EvokerFangs) {
shieldBlockEvent(e.getEntity(),e,1D);
}
}
}
}
@EventHandler
public void onPotionEffect(EntityPotionEffectEvent event) {
// 检查效果是否是中毒效果
if (event.getNewEffect() != null && event.getNewEffect().getType() == PotionEffectType.POISON) {
// 检查目标是否是玩家
if (event.getEntity() instanceof Player) {
// 取消中毒效果
event.setCancelled(true);
}
}
}
public void shieldBlockEvent(Entity entity,EntityDamageByEntityEvent e,double damage){
Player player = (Player) entity;
if(CDTimeAPI.isCD(entity.getUniqueId(),"invincible")){
player.playSound(player.getLocation(),Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR,1,1);
e.setCancelled(true);
return;
}
ItemStack offHandItem = player.getInventory().getItemInOffHand();
// 检查副手是否有盾牌
if (offHandItem != null && offHandItem.getType() == Material.SHIELD && player.isBlocking()) {
// 取消伤害事件
e.setCancelled(true);
// 减少盾牌的耐久
short durability = offHandItem.getDurability();
offHandItem.setDurability((short) (durability + 18)); // 增加1点耐久损耗
player.playSound(player.getLocation(),Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR,1,1);
// 如果盾牌的耐久已经耗尽移除盾牌
if (offHandItem.getDurability() >= offHandItem.getType().getMaxDurability()) {
player.getInventory().setItemInOffHand(null); // 清空副手
player.playSound(player.getLocation(),Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR,1,1);
}
}else {
e.setDamage(damage);
}
}
}

View File

@ -0,0 +1,131 @@
package com.yutian.minerwar.listener;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import com.yutian.minerwar.game.Point;
import com.yutian.minerwar.game.Region;
import org.bukkit.Material;
import org.bukkit.Sound;
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.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.*;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
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.player.PlayerPickupItemEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.Iterator;
public class GamePotect implements Listener {
@EventHandler // 取消生物燃烧
public void onEntityCombust(EntityCombustEvent event) {
if (event.getEntity() instanceof LivingEntity) {
event.setCancelled(true);
}
}
@EventHandler // 禁止火焰燃烧方块
public void onBlockFire(BlockBurnEvent e) {
e.setCancelled(true);
}
@EventHandler// 禁止火焰燃烧物品
public void onBlockIgnite(BlockIgniteEvent e) {
e.setCancelled(true);
}
@EventHandler(priority= EventPriority.HIGH)
public void onWeatherChange(WeatherChangeEvent e) {
e.setCancelled(true);
}
@EventHandler /*保护农作物免踩踏*/
public void onJumpFarm(PlayerInteractEvent e){
if (e.isCancelled()) {return;}
if(e.getAction() == Action.PHYSICAL){
Block block = e.getClickedBlock();
if(block.getType() == Material.FARMLAND){
e.setCancelled(true);
}
}
}
@EventHandler /*保护农作物免踩踏*/
public void onMobsFarm(EntityInteractEvent e){
if (e.isCancelled()) {return;}
if(e.getEntityType() != EntityType.PLAYER){
Block block = e.getBlock();
if(block.getType() == Material.FARMLAND){
e.setCancelled(true);
}
}
}
@EventHandler
public void onClick(InventoryClickEvent e){
Player p = (Player) e.getWhoClicked();
}
@EventHandler // 禁止丢弃任何物品
public void onDrop(PlayerDropItemEvent e){
Game game = MinerWar.getGame();
game.effect_RefreshExcavateAmount(e.getPlayer()); // 刷新玩家背包中的粗金
e.setCancelled(true);
/*if(e.getItemDrop().getItemStack().getType().equals(Material.RAW_GOLD)) {
e.setCancelled(true);
}*/
}
@EventHandler
public void onBreakProtectedArea(BlockBreakEvent e){
Player p = e.getPlayer();
Game game = MinerWar.getGame();
Block block = e.getBlock();
if(block.getType() == Material.GOLD_ORE) {
e.setCancelled(false);
}else if(block.getType() == Material.COBBLESTONE) {
e.setCancelled(false);
} else {
e.setCancelled(true);
}
}
@EventHandler
public void onPlaceProtectedArea(BlockPlaceEvent e){
Player p = e.getPlayer();
Game game = MinerWar.getGame();
Block block = e.getBlock();
e.setCancelled(true);
}
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
Game game = MinerWar.getGame();
if(game.isStarted()){
Iterator<Block> iterator = event.blockList().iterator();
while (iterator.hasNext()) {
Block block = iterator.next();
Point min = new Point(21,68,-16);
Point max = new Point(39,90,-5);
Region region = new Region(game.getVillagerPoint().getWorld(),min,max);
if (region.isInRegion(block.getLocation())) {
iterator.remove();
}
}
}
}
}

View File

@ -0,0 +1,32 @@
package com.yutian.minerwar.listener;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class JoinListener implements Listener {
private final Game game;
public JoinListener(){
game = MinerWar.getGame();
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
new BukkitRunnable() {
@Override
public void run() {
if(!game.isStarted()) {
game.start();
}
player.getInventory().clear();
game.initPlayerData(e.getPlayer());
}
}.runTaskLater(MinerWar.inst(),10L);
}
}

View File

@ -0,0 +1,109 @@
package com.yutian.minerwar.listener;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Game;
import com.yutian.minerwar.game.Region;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import tools.RandomUtil;
import java.util.HashMap;
public class KeepEntitiesOnDeath implements Listener {
public static HashMap<Player,Integer> deathsVaule = new HashMap<>();
@EventHandler
public void onAutoRespawn(PlayerDeathEvent e) {
e.setDeathMessage(null);
Player p = e.getEntity();
if(!deathsVaule.containsKey(p)){
deathsVaule.put(p,1);
}else {
deathsVaule.put(p,deathsVaule.get(p)+1);
}
int deathAmount = deathsVaule.get(p);
new BukkitRunnable() {
private int i = 0;
public void run() {
if (i == 1) {
p.spigot().respawn();
}
if(i == 3) {
p.sendTitle("§4你嘎了", "§6累积死亡: "+deathAmount+"");
}
if(i == 4) {
Game game = MinerWar.getGame();
Region region = game.getGameRegion();
int newX = RandomUtil.getRandomInt((int) region.getMin().getX(), (int) region.getMax().getX());
int newZ = RandomUtil.getRandomInt((int) region.getMin().getZ(), (int) region.getMax().getZ());
Block theHighestBlock = region.getWorld().getHighestBlockAt(newX,newZ);
p.teleport(theHighestBlock.getLocation().add(0,1,0));
if(!p.getAllowFlight()){
p.setAllowFlight(true);
}
deathDropsCoarseGold(p,deathAmount);
cancel();
}
i++;
}
}.runTaskTimer(MinerWar.inst(),0L, 2L);
}
/*死亡惩罚
* 累积死亡6次 掉落粗金 20%
* 累积死亡11次 掉落粗金 30%
* 累积死亡16次 掉落粗金 40%
* 累积死亡21次 掉落粗金 50%
* */
public static void deathDropsCoarseGold(Player player,int deathAmount){
Game game = MinerWar.getGame();
double scale = 0.1;
if(deathAmount >= 21){
scale = 0.5;
}else if(deathAmount >= 16){
scale = 0.4;
}else if(deathAmount >= 11){
scale = 0.3;
}else if(deathAmount >= 6){
scale = 0.2;
}
int rawGoldAmount = game.getExcavateAmount(player); // 获取玩家有多少粗金
int dropRawGold = (int) (rawGoldAmount * scale);// 获取本次死亡会掉落多少粗金
if(dropRawGold >= 1) {
player.sendMessage("§c[消息] §a丢失了§e"+dropRawGold+"块§a黄金");
setBackpackThickGoldTime(player, rawGoldAmount - dropRawGold);
game.effect_RefreshExcavateAmount(player);
}
}
// 获取玩家背包有多少粗金
public static void setBackpackThickGoldTime(Player player,int residualCrudeGold){
Inventory inv = player.getInventory();
for (int i = 0; i < 36; i++) {
ItemStack item = inv.getItem(i);
if (item != null && item.getType() != Material.AIR) {
if (item.getType().equals(Material.RAW_GOLD)) {
inv.setItem(i, new ItemStack(Material.AIR));
}
}
}
if (residualCrudeGold >= 1) {
ItemStack rawGold = new ItemStack(Material.RAW_GOLD,residualCrudeGold);
player.getInventory().addItem(rawGold);
}
}
}

View File

@ -0,0 +1,60 @@
package com.yutian.minerwar.listener;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.data.RepairGiftGui;
import com.yutian.minerwar.game.Game;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class PlayerListener implements Listener {
private Game game;
public PlayerListener(){
game = MinerWar.getGame();
}
@EventHandler
public void onPick(PlayerDropItemEvent e) {
Player p = e.getPlayer();
if (game.isStarted()) {
if (p.isSneaking()) {
p.setFoodLevel(4);
p.setHealth(6);
RepairGiftGui.OpenGui(p);
}
}
}
/*
* 主播可进行二段跳
* */
@EventHandler
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE) {
return;
}
event.setCancelled(true);
player.setAllowFlight(false);
player.setFlying(false);
player.setVelocity(player.getLocation().getDirection().multiply(0.6).setY(0.6));
player.playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 10);
player.playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 0.2F, 1.0F);
new BukkitRunnable() {
@Override
public void run() {
if(!player.getAllowFlight()){
player.setAllowFlight(true);
}
}
}.runTaskLater(MinerWar.inst(),20L);
}
}

View File

@ -0,0 +1,99 @@
package com.yutian.minerwar.liveevent;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.effects.PotionBlindness;
import com.yutian.minerwar.effects.ShoutArrow;
import com.yutian.minerwar.effects.SummonTheBee;
import com.yutian.minerwar.effects.SummonTheEvokerFang;
import com.yutian.minerwar.game.Game;
import com.yutian.minerwar.listener.KeepEntitiesOnDeath;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import tools.CDTimeAPI;
import tools.GameUtil;
import java.util.UUID;
public class GiftEventHandler {
public static void SendHandLer(Player zhubo, String userName, String eventName){
Game game = MinerWar.getGame();
userName = GameUtil.hideName(userName);
if (eventName.equalsIgnoreCase("螺旋升天")) {
} else if (eventName.contains("瞬间加血")) {
int heal = 1;
int stringHeal = Integer.parseInt(eventName.replace("瞬间加血",""));
if(stringHeal >= 1){
heal = stringHeal;
}
int newHeal = (int) Math.min(zhubo.getHealth() + heal, 20);
zhubo.setHealth(newHeal);
zhubo.playSound(zhubo.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1,1);
zhubo.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,zhubo.getLocation().add(0,1,0),20,0.1,0.1,0.1,0.3);
} else if (eventName.equalsIgnoreCase("天使庇护")) {
UUID uuid = zhubo.getUniqueId();
String timepieceKey = "angelicSanctuary";
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * 10);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * 10);
}
int deathAmount = 0;
if(KeepEntitiesOnDeath.deathsVaule.get(zhubo) != null){
deathAmount = KeepEntitiesOnDeath.deathsVaule.get(zhubo);
}
int newAmount = deathAmount - 3;
if(newAmount <= 0){
newAmount = 0;
}
KeepEntitiesOnDeath.deathsVaule.put(zhubo,newAmount);
} else if (eventName.equalsIgnoreCase("超级挖掘")) {
UUID uuid = zhubo.getUniqueId();
String timepieceKey = "supermining";
if(CDTimeAPI.isCD(uuid,timepieceKey)){
long newTime = CDTimeAPI.getCD(uuid,timepieceKey) + (1000L * 30);
CDTimeAPI.setPlayerCD(uuid,timepieceKey,newTime);
} else {
CDTimeAPI.setPlayerCD(uuid,timepieceKey,1000L * 30);
}
int deathAmount = 0;
if(KeepEntitiesOnDeath.deathsVaule.get(zhubo) != null){
deathAmount = KeepEntitiesOnDeath.deathsVaule.get(zhubo);
}
int newAmount = deathAmount - 1;
if(newAmount <= 0){
newAmount = 0;
}
KeepEntitiesOnDeath.deathsVaule.put(zhubo,newAmount);
} else if (eventName.equalsIgnoreCase("致盲3秒")) {
if(CDTimeAPI.isCD(zhubo.getUniqueId(),"angelicSanctuary")){return;}
PotionBlindness.apply(game,zhubo,3);
} else if (eventName.contains("小蜜蜂X")) {
if(CDTimeAPI.isCD(zhubo.getUniqueId(),"angelicSanctuary")){return;}
String[] eventSp = eventName.toUpperCase().split("X");
int amount = Integer.parseInt(eventSp[1]);
SummonTheBee.apply(game, zhubo, userName, amount);
} else if (eventName.contains("箭头")) {
if(CDTimeAPI.isCD(zhubo.getUniqueId(),"angelicSanctuary")){return;}
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]);
}
ShoutArrow.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]);
}
SummonTheEvokerFang.apply(game, zhubo, userName, amount);
}
}
}

View File

@ -0,0 +1,27 @@
package com.yutian.minerwar.liveevent;
import com.io.yutian.mclive.event.LiveGiftEvents;
import com.yutian.minerwar.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);
if(e.getUser().nickName() != null) {
userName = e.getUser().nickName();
}
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);
}
}

View File

@ -0,0 +1,35 @@
package com.yutian.minerwar.liveevent;
import com.io.yutian.pixelliveplugin.event.KeyInputEvent;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.manager.GameManager;
import net.royawesome.jlibnoise.module.combiner.Min;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class KeyInputListener implements Listener {
public List<UUID> uuidList = new ArrayList<>();
public boolean resetByMistake = false;
@EventHandler//点赞
public void onDianZan(KeyInputEvent e) {
Player zhubo = e.getPlayer();
GameManager manager = MinerWar.getGameManager();
if (manager.isKeyInputd()) {
zhubo.sendMessage("Modifiers = "+e.getModifiers() + " KeyCode = "+e.getKeyCode()+" RawCode = "+e.getRawCode());
}
}
}

View File

@ -0,0 +1,39 @@
package com.yutian.minerwar.liveevent;
import com.io.yutian.mclive.event.LiveLikeEvents;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.data.LikeData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import tools.GameUtil;
import tools.RandomUtil;
import java.util.HashMap;
public class LikeListener implements Listener {
@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 = MinerWar.getGameManager().getLikeDataMap();
for (String key : likeDataMap.keySet()){
LikeData likeData = likeDataMap.get(key);
likeData.addNowAmount((int)add_amount);
if(likeData.meetTheQuantityRequirement()){
String eventName = likeData.getEffectKey();
String title = "§c"+eventName;
String subtitle = "§9双击屏幕x"+likeData.getNeedAmount();
likeData.OutPlaySoundsEvent();
zhubo.sendTitle(title, subtitle,0, 30, 10);
GiftEventHandler.SendHandLer(zhubo,userName,eventName);
likeData.setNowAmount(0);
}
}
}
}

View File

@ -0,0 +1,127 @@
package com.yutian.minerwar.manager;
import com.io.yutian.mclive.event.ZhuboAPI;
import com.yutian.minerwar.data.GiftData;
import com.yutian.minerwar.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.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
public class GameManager {
private File manageFile;
private FileConfiguration manageConfig;
private boolean keyInputd = false;
private int goldOreGoal;
private int gameGoal;
private long gameTime;
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);
gameGoal = manageConfig.getInt("挑战目标",5);
Bukkit.getConsoleSender().sendMessage("挑战完成次数: "+gameGoal+"");
goldOreGoal = manageConfig.getInt("金矿数量",200);
Bukkit.getConsoleSender().sendMessage("金矿采集数量: "+goldOreGoal+"");
gameTime = manageConfig.getLong("游戏时间定格",5500L);
Bukkit.getConsoleSender().sendMessage("游戏时间定格: "+gameTime+"");
}
public void loadRandomBoxPlugin() {
if(Bukkit.getPluginManager().getPlugin("RandomBox") != null){
isRandomBox = true;
Bukkit.getConsoleSender().sendMessage("- 随机盲盒: 已启用");
} else {
isRandomBox = false;
Bukkit.getConsoleSender().sendMessage("- 随机盲盒: 未启用");
}
}
public void saveGameSettings() {
manageConfig.set("游戏时间定格",gameTime);
try {
manageConfig.save(manageFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void setKeyInputd(boolean keyInputd) {
this.keyInputd = keyInputd;
}
public boolean isKeyInputd() {
return keyInputd;
}
public int getGameGoal() {
return gameGoal;
}
public int getGoldOreGoal() {return goldOreGoal;}
public long getGameTime() {
return gameTime;
}
public void setGameTime(long gameTime) {
this.gameTime = gameTime;
}
public static boolean isIsRandomBox() {
return isRandomBox;
}
// 判断哪个点赞整蛊效果已达到要求可触发
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;
}
}

View File

@ -0,0 +1,76 @@
package com.yutian.minerwar.util;
import com.yaohun.RandomBox.api.RBoxAPI;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.data.GiftData;
import com.yutian.minerwar.liveevent.GiftEventHandler;
import com.yutian.minerwar.manager.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 = MinerWar.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(MinerWar.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;
}
}

View File

@ -0,0 +1,23 @@
package com.yutian.minerwar.util;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import java.util.Arrays;
public class MerchantRecipeUtil {
public static MerchantRecipe buildMerchantRecipe(Material material, int amount, int price) {
MerchantRecipe merchantRecipe = new MerchantRecipe(new ItemStack(material, amount), Integer.MAX_VALUE);
merchantRecipe.setIngredients(Arrays.asList(new ItemStack(Material.RAW_GOLD, price)));
return merchantRecipe;
}
public static MerchantRecipe buildMerchantRecipe(ItemStack itemStack, int price) {
MerchantRecipe merchantRecipe = new MerchantRecipe(itemStack, Integer.MAX_VALUE);
merchantRecipe.setIngredients(Arrays.asList(new ItemStack(Material.RAW_GOLD, price)));
return merchantRecipe;
}
}

View File

@ -0,0 +1,107 @@
package com.yutian.minerwar.util;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.math.BlockVector3;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.game.Region;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import tools.RandomUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class discardCode {
public void initGoldOreGenerate(){
Region region = MinerWar.getGame().getGameRegion();
Bukkit.getConsoleSender().sendMessage("[日志 - 矿工战争] 游戏场地:");
long startGoldTime = System.currentTimeMillis(); // 记录开始时间
List<Location> chunkStartLocations = new ArrayList<>();
// 获取区域的最小和最大坐标
int regionMinX = (int) Math.floor(region.getMin().getX());
int regionMaxX = (int) Math.floor(region.getMax().getX());
int regionMinZ = (int) Math.floor(region.getMin().getZ());
int regionMaxZ = (int) Math.floor(region.getMax().getZ());
World world = region.getWorld(); // 假设 Region 可以获取 World 对象
// 按区块16x16的范围迭代
for (int x = regionMinX; x <= regionMaxX; x += 30) {
for (int z = regionMinZ; z <= regionMaxZ; z += 30) {
// 计算每个区块的左上角位置 (x=0, z=0 对应的局部位置)
int newX = x + RandomUtil.getRandomInt(-10,10);
int newZ = z + RandomUtil.getRandomInt(-10,10);
Block highestBlock = world.getHighestBlockAt(newX, newZ);
Material blockType = highestBlock.getType();
if (blockType.equals(Material.AIR) || blockType.name().contains("WATER") || blockType.name().contains("LAVA")) {
}else {
chunkStartLocations.add(highestBlock.getLocation()); // 将区块起始位置添加到列表
}
}
}
// 输出结果调试查看区块的起始位置
Bukkit.getConsoleSender().sendMessage(" - 区块数量: "+chunkStartLocations.size()+"");
Collections.shuffle(chunkStartLocations);
List<Location> locationList = new ArrayList<>();
for (Location location : chunkStartLocations) {
if (locationList.size() >= MinerWar.getGameManager().getGoldOreGoal()) {
break;
}
Location loc = location.add(0,1,0);
world.getBlockAt(loc).setType(Material.GOLD_ORE);
locationList.add(loc);
}
long GoldendTime = System.currentTimeMillis(); // 记录结束时间
long Goldduration = GoldendTime - startGoldTime; // 计算耗时
Bukkit.getConsoleSender().sendMessage(" - 金矿坐标: 已储存 "+Goldduration+" ms");
Bukkit.getConsoleSender().sendMessage(" - 清理杂草: 启动中");
long startGrassTime = System.currentTimeMillis(); // 记录开始时间
// 清理这个区域中所有的非白名单方块
for (int y = 60; y <= 130; y++) {
for (int x = (int) Math.floor(region.getMin().getX()-50); x <= region.getMax().getX()+50; x++) {
for (int z = (int) Math.floor(region.getMin().getZ()-50); z <= region.getMax().getZ()+50; z++) {
Block block = region.getWorld().getBlockAt(x, y, z);
if (!block.getType().equals(Material.AIR)) {
if(block.getType() == Material.TALL_GRASS){
block.setType(Material.AIR);
}else if(block.getType() == Material.SUNFLOWER){
block.setType(Material.AIR);
}else if(block.getType() == Material.GRASS){
if(RandomUtil.getRandomInt(100,1) < 70) {
block.setType(Material.AIR);
}
}
}
}
}
}
long endTime = System.currentTimeMillis(); // 记录结束时间
long duration = endTime - startGrassTime; // 计算耗时
Bukkit.getConsoleSender().sendMessage(" - 清理杂草: 清理完成 "+duration+" ms");
File schema_file = new File("plugins/FastAsyncWorldEdit/schematics","spawn.schem");
Location location = new Location(world, 0,72,0);
EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world));
Bukkit.getScheduler().runTaskAsynchronously(
MinerWar.inst(), () -> {
try {
Clipboard clipboard = ClipboardFormats.findByFile(schema_file).load(schema_file);
clipboard.paste(BukkitAdapter.adapt(world), BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
clipboard.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
editSession.close();
}
}
);
Bukkit.getConsoleSender().sendMessage(" - 村民小屋: 已刷新");
}
}

View File

@ -0,0 +1,43 @@
package tools;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import java.util.List;
public class BossBarUtil {
public static void setBarColor(BossBar bossBar, double percent){
if (percent >= 0 && percent <= 0.3333) {
bossBar.setColor(BarColor.RED);
} else if (percent <= 0.6666) {
bossBar.setColor(BarColor.YELLOW);
} else {
bossBar.setColor(BarColor.GREEN);
}
}
public static void setBarProgress(BossBar bossBar,double percent){
if (percent <= 0) {
percent = 0;
} else if (percent >= 1) {
percent = 1;
}
bossBar.setProgress(percent);
}
// BossBarUtil.addBossBar(player,new ArrayList<>(Arrays.asList(bossBar1,bossBar3,bossBar2)));
public static void addBossBar(Player player, List<BossBar> bossBarList){
for (BossBar bossBar : bossBarList) {
bossBar.addPlayer(player);
}
}
public static void removeBossBar(Player player,List<BossBar> bossBarList){
for (BossBar bossBar : bossBarList) {
bossBar.removePlayer(player);
}
}
}

View File

@ -0,0 +1,66 @@
package tools;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
public class CDTimeAPI {
private static HashSet<CDData> cdData = new HashSet<>();
public static void setPlayerCD(UUID uuid, String key, long mills) {
CDData data = getCDData(uuid);
long now = System.currentTimeMillis();
data.setCD(key, now + mills);
}
public static long getCD(UUID uuid, String key) {
CDData data = getCDData(uuid);
long now = System.currentTimeMillis();
return data.getCD(key) - now;
}
public static boolean isCD(UUID uuid, String key) {
return (getCD(uuid, key) > 0L);
}
public static CDData getCDData(UUID uuid) {
for (CDData cDData : cdData) {
if (cDData.getUuid().equals(uuid))
return cDData;
}
CDData data = new CDData(uuid);
cdData.add(data);
return data;
}
public static class CDData{
private final UUID uuid;
private final HashMap<String, Long> cdTime;
public CDData(UUID uuid) {
this.uuid = uuid;
this.cdTime = new HashMap<>();
}
public UUID getUuid() {
return this.uuid;
}
public void setCD(String key, long time) {
this.cdTime.put(key, time);
}
public long getCD(String key) {
return this.cdTime.getOrDefault(key,-1L);
}
public HashMap<String, Long> getCdTime() {
return cdTime;
}
}
public static HashSet<CDData> getCdData() {
return cdData;
}
}

View File

@ -0,0 +1,62 @@
package tools;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.io.File;
public class GameUtil {
public static String hideName(String audience) {
if (audience.length() <= 2) {
return "**";
}
char firstChar = audience.charAt(0);
char lastChar = audience.charAt(audience.length() - 1);
StringBuilder maskedString = new StringBuilder();
for (int i = 1; i < audience.length() - 1; i++) {
maskedString.append('*');
}
return String.valueOf(firstChar) + maskedString + lastChar;
}
public static void sendMessage(CommandSender sender, String message) {
sender.sendMessage("§c[系统]§a" + message);
}
public static void sendAllSound(String sound) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (sound.contains("_")) {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
} else {
player.playSound(player.getLocation(), sound, 0.5F, 1);
}
}
}
public static void sendAllTitle(String title,String subTitle,int t1,int t2,int t3) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendTitle(title,subTitle,t1,t2,t3);
}
}
public static Vector getRandomVector(double radius){
double x = RandomUtil.getRandomDouble(0-radius, 0+radius, 1);
double y = RandomUtil.getRandomDouble(0, 0.5, 1);
double z = RandomUtil.getRandomDouble(0-radius, 0+radius, 1);
return new Vector(x, y, z);
}
public static Vector getRandomVector(double radius,double radiusY){
double x = RandomUtil.getRandomDouble(0-radius, 0+radius, 1);
double y = RandomUtil.getRandomDouble(0+radiusY, 0.5+radiusY, 1);
double z = RandomUtil.getRandomDouble(0-radius, 0+radius, 1);
return new Vector(x, y, z);
}
}

View File

@ -0,0 +1,36 @@
package tools;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.Random;
public class RandomUtil {
public static boolean random(double d) {
return d >= new Random().nextFloat();
}
public static int getRandomInt(int min, int max) {
if (min == max) {
return max;
}
Random r = new Random();
int i = min < max ? min : max;
int a = min < max ? max : min;
return r.nextInt(a - i + 1) + i;
}
public static double getRandomDouble(double min, double max, int scl) {
int pow = (int) Math.pow(10, scl);
return Math.floor((Math.random() * (max - min) + min) * pow) / pow;
}
public static Location getRandomLocation(World world, double minX, double maxX, double minY, double maxY, double minZ, double maxZ) {
double rx = getRandomDouble(minX, maxX, 3);
double ry = getRandomDouble(minY, maxY, 3);
double rz = getRandomDouble(minZ, maxZ, 3);
return new Location(world, rx, ry, rz);
}
}

View File

@ -0,0 +1,93 @@
package tools;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import java.util.ArrayList;
import java.util.List;
public class StackUtil {
public static ItemStack diamondSword(){
ItemStack item = new ItemStack(Material.DIAMOND_SWORD);
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setUnbreakable(true);
item.setItemMeta(meta);
return item;
}
public static ItemStack ironPickaxe(){
ItemStack item = new ItemStack(Material.IRON_PICKAXE);
ItemMeta meta = item.getItemMeta();
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;
}
public static ItemStack bow(){
ItemStack item = new ItemStack(Material.BOW);
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.addEnchant(Enchantment.ARROW_DAMAGE,2,true);
meta.setUnbreakable(true);
item.setItemMeta(meta);
return item;
}
public static ItemStack bloodBag(){
ItemStack item = new ItemStack(Material.POTATO);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§c§l小血瓶");
List<String> lore = new ArrayList<>();
lore.add("§a★§7恢复生命的药剂");
lore.add("§c❤");
meta.setLore(lore);
meta.setCustomModelData(801);
item.setItemMeta(meta);
return item;
}
public static ItemStack bigBloodBag(){
ItemStack item = new ItemStack(Material.POTATO);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§c§l大血瓶");
List<String> lore = new ArrayList<>();
lore.add("§a★§7恢复生命的药剂");
lore.add("§c❤❤❤");
meta.setLore(lore);
meta.setCustomModelData(802);
item.setItemMeta(meta);
return item;
}
public static ItemStack extraGradeBloodPack(){
ItemStack item = new ItemStack(Material.POTATO);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("§c§l特级血瓶");
List<String> lore = new ArrayList<>();
lore.add("§a★§7恢复生命的药剂");
lore.add("§c❤❤❤❤❤");
meta.setLore(lore);
meta.setCustomModelData(803);
item.setItemMeta(meta);
return item;
}
}

View File

@ -0,0 +1,2 @@
completeAmount: 10
countdownTime: 10

View File

@ -0,0 +1,13 @@
name: MinerWar
main: com.yutian.minerwar.MinerWar
version: 1.0
api-version: '1.20'
authors: [ SuperYuTian ]
softdepend:
- NBTAPI
- McLiveAPI
- FastAsyncWorldEdit
commands:
game:
gameedit:
livegift: