From dafbc09075e604f6f0c56a4eba6bed28a1985973 Mon Sep 17 00:00:00 2001 From: yaohunya <31456652@qq.com> Date: Mon, 21 Oct 2024 11:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=882.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutian/minerwar/game/Game.java | 15 +++++++++++ .../yutian/minerwar/listener/GamePotect.java | 25 ++++++++++++++++++- .../listener/KeepEntitiesOnDeath.java | 9 ++++--- .../minerwar/listener/PlayerListener.java | 4 +-- .../minerwar/liveevent/GiftEventHandler.java | 12 +++------ src/main/java/tools/StackUtil.java | 2 ++ 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yutian/minerwar/game/Game.java b/src/main/java/com/yutian/minerwar/game/Game.java index 53e5e5a..a0eaaa8 100644 --- a/src/main/java/com/yutian/minerwar/game/Game.java +++ b/src/main/java/com/yutian/minerwar/game/Game.java @@ -107,7 +107,20 @@ public class Game { } }.runTaskTimer(MinerWar.inst(),0L,10L); tasks.add(task); + // 启动任务,定期检查时间并切换白天和黑夜 + BukkitTask worldTimeTask = new BukkitRunnable() { + @Override + public void run() { + // 获取当前世界时间 + long currentTime = world.getTime(); + // 每秒加快 2 ticks,使其加速一倍(10 分钟一个昼夜) + world.setTime(currentTime + 3); + } + }.runTaskTimer(MinerWar.inst(),0L,1L); + tasks.add(worldTimeTask); } + + public void stop(){ villagerShop.remove(); for (Player player1 : Bukkit.getOnlinePlayers()){ @@ -126,6 +139,8 @@ public class Game { bossBar1.addPlayer(player); bossBar2.addPlayer(player); initPlayerBackpack(player); + Location location = new Location(player.getWorld(),6.5,78.0,-75.5,90,0); + player.teleport(location); } public void initPlayerBackpack(Player player){ diff --git a/src/main/java/com/yutian/minerwar/listener/GamePotect.java b/src/main/java/com/yutian/minerwar/listener/GamePotect.java index dd6af01..bd78038 100644 --- a/src/main/java/com/yutian/minerwar/listener/GamePotect.java +++ b/src/main/java/com/yutian/minerwar/listener/GamePotect.java @@ -22,6 +22,8 @@ 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.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; @@ -76,7 +78,19 @@ public class GamePotect implements Listener { @EventHandler public void onClick(InventoryClickEvent e){ + int rawSlot = e.getRawSlot(); Player p = (Player) e.getWhoClicked(); + Inventory inv = e.getInventory(); + if(inv.getType() == InventoryType.CRAFTING){ + if(rawSlot == 36 || rawSlot == 37 || rawSlot == 38){ + e.setCancelled(true); + } + } + if(inv.getType() == InventoryType.MERCHANT){ + if(rawSlot == 30 || rawSlot == 31 || rawSlot == 32){ + e.setCancelled(true); + } + } } @EventHandler // 禁止丢弃任何物品 @@ -86,7 +100,16 @@ public class GamePotect implements Listener { e.setCancelled(true); /*if(e.getItemDrop().getItemStack().getType().equals(Material.RAW_GOLD)) { e.setCancelled(true); - }*/ + }*/ + } + + @EventHandler + public void onCloseInv(InventoryCloseEvent e){ + Player player = (Player) e.getPlayer(); + Inventory inventory = e.getInventory(); + if(inventory.getType().equals(InventoryType.MERCHANT)){ + MinerWar.getGame().effect_RefreshExcavateAmount(player); + } } diff --git a/src/main/java/com/yutian/minerwar/listener/KeepEntitiesOnDeath.java b/src/main/java/com/yutian/minerwar/listener/KeepEntitiesOnDeath.java index cf7e860..a7bef8d 100644 --- a/src/main/java/com/yutian/minerwar/listener/KeepEntitiesOnDeath.java +++ b/src/main/java/com/yutian/minerwar/listener/KeepEntitiesOnDeath.java @@ -82,9 +82,12 @@ public class KeepEntitiesOnDeath implements Listener { scale = 0.2; } int rawGoldAmount = game.getExcavateAmount(player); // 获取玩家有多少粗金 - int dropRawGold = (int) (rawGoldAmount * scale);// 获取本次死亡会掉落多少粗金 - if(dropRawGold >= 1) { - player.sendMessage("§c[消息] §a丢失了§e"+dropRawGold+"块§a黄金!"); + if(rawGoldAmount >= 1) { + int dropRawGold = (int) (rawGoldAmount * scale);// 获取本次死亡会掉落多少粗金 + if (dropRawGold <= 1) { + dropRawGold = 1; + } + player.sendMessage("§c[消息] §a丢失了§e" + dropRawGold + "块§a黄金!"); setBackpackThickGoldTime(player, rawGoldAmount - dropRawGold); game.effect_RefreshExcavateAmount(player); } diff --git a/src/main/java/com/yutian/minerwar/listener/PlayerListener.java b/src/main/java/com/yutian/minerwar/listener/PlayerListener.java index a661644..03135eb 100644 --- a/src/main/java/com/yutian/minerwar/listener/PlayerListener.java +++ b/src/main/java/com/yutian/minerwar/listener/PlayerListener.java @@ -26,8 +26,8 @@ public class PlayerListener implements Listener { Player p = e.getPlayer(); if (game.isStarted()) { if (p.isSneaking()) { - p.setFoodLevel(4); - p.setHealth(6); + // p.setFoodLevel(4); + // p.setHealth(6); RepairGiftGui.OpenGui(p); } } diff --git a/src/main/java/com/yutian/minerwar/liveevent/GiftEventHandler.java b/src/main/java/com/yutian/minerwar/liveevent/GiftEventHandler.java index 66100df..8c9b8fa 100644 --- a/src/main/java/com/yutian/minerwar/liveevent/GiftEventHandler.java +++ b/src/main/java/com/yutian/minerwar/liveevent/GiftEventHandler.java @@ -10,6 +10,8 @@ import com.yutian.minerwar.listener.KeepEntitiesOnDeath; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import tools.CDTimeAPI; import tools.GameUtil; @@ -22,14 +24,8 @@ public class GiftEventHandler { 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); + } else if (eventName.equalsIgnoreCase("瞬间加血")) { + zhubo.addPotionEffect(new PotionEffect(PotionEffectType.HEAL,3,0)); 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("天使庇护")) { diff --git a/src/main/java/tools/StackUtil.java b/src/main/java/tools/StackUtil.java index cae7c2e..c7057dd 100644 --- a/src/main/java/tools/StackUtil.java +++ b/src/main/java/tools/StackUtil.java @@ -17,6 +17,7 @@ public class StackUtil { ItemStack item = new ItemStack(Material.DIAMOND_SWORD); ItemMeta meta = item.getItemMeta(); meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + meta.addEnchant(Enchantment.DAMAGE_ALL,4,true); meta.setUnbreakable(true); item.setItemMeta(meta); return item; @@ -25,6 +26,7 @@ public class StackUtil { ItemStack item = new ItemStack(Material.IRON_PICKAXE); ItemMeta meta = item.getItemMeta(); meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + meta.addEnchant(Enchantment.DIG_SPEED,3,true); meta.setUnbreakable(true); item.setItemMeta(meta); return item;