From 76f5c3f9a5062fbb2d5a5eae26bb01bd84042954 Mon Sep 17 00:00:00 2001 From: yuyu <124714592@qq.com> Date: Sat, 16 Mar 2024 09:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E4=B8=BB=E6=A1=86=E6=9E=B6=EF=BC=8C=E5=8C=BA=E5=88=86=E4=BA=86?= =?UTF-8?q?=E6=AF=8F=E4=B8=AA=E7=94=9F=E7=89=A9=E7=BE=A4=E7=B3=BB=E7=9A=84?= =?UTF-8?q?=E5=8D=B1=E9=99=A9=E5=BA=A6=EF=BC=8C=E4=BD=86=E6=98=AF=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E6=B2=A1=E6=9C=89=E5=85=B7=E4=BD=93=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8C=E7=94=9F=E7=89=A9=E7=BE=A4=E7=B3=BB=E7=9A=84?= =?UTF-8?q?id=E6=88=96=E8=80=85=E5=90=8D=E7=A7=B0=EF=BC=8C=E6=89=80?= =?UTF-8?q?=E4=BB=A5=E7=94=A8a=E4=BB=A3=E6=9B=BF=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sakurarealm/playerrisk/PlayerRisk.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java b/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java index 312af99..451351b 100644 --- a/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java +++ b/src/main/java/com/sakurarealm/playerrisk/PlayerRisk.java @@ -13,6 +13,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import java.util.*; @@ -21,6 +22,13 @@ public final class PlayerRisk extends JavaPlugin implements Listener { PlayerRiskManager playerRiskManager = null; + //假设的方法,您需要根据实际情况来实现它 + private String getCurrentBiome(Player player) { + //实现获取玩家当前所在生物群系的逻辑 + return player.getLocation().getBlock().getBiome().name(); + } + + public PlayerRiskManager getPlayerRiskManager() { if (playerRiskManager == null) { throw new NullPointerException("PlayerRisk plugin is not initialized."); @@ -52,6 +60,16 @@ public final class PlayerRisk extends JavaPlugin implements Listener { // Plugin shutdown logic } + /** + * 玩家退出游戏后从map集合中移出 + * @param event + */ + @EventHandler + public void playerOffOnline(PlayerQuitEvent event){ + Player player = event.getPlayer(); + playerRiskManager.removePlayerLevel(player.getName()); + getLogger().info(ChatColor.GREEN+player.getName()+"退出了游戏"); + } /** * TODO: 当玩家进入城镇时, 危险度不再增加. @@ -63,7 +81,7 @@ public final class PlayerRisk extends JavaPlugin implements Listener { //当玩家进入城镇后,移出map集合并且清零 Player player = event.getPlayer(); playerRiskManager.removePlayerLevel(player.getName()); - throw new NotImplementedException("Not implemented yet."); + } /** @@ -76,11 +94,10 @@ public final class PlayerRisk extends JavaPlugin implements Listener { //当玩家离开城镇后,把玩家姓名放入mao中 Player player = event.getPlayer(); - //此处应该有一个方法,用来获取生物群系的姓名或者id,在方法中默认只有一个群系,用字符a代替 - playerRiskManager.addPlayerToMap(player.getName(),"a"); + playerRiskManager.addPlayerToMap(player.getName(),getCurrentBiome(player)); + - throw new NotImplementedException("Not implemented yet."); } /** @@ -92,7 +109,7 @@ public final class PlayerRisk extends JavaPlugin implements Listener { public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); playerRiskManager.removePlayerLevel(player.getName()); - throw new NotImplementedException("Not implemented yet."); + } // TODO: Add any other event handlers needed to manage player risk.