Skip to content

Commit

Permalink
Bug Fix: Player Quit Without Ending Q&A
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuihui1022 committed Feb 7, 2024
1 parent ed2eb10 commit 93dfc0d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>top.mpt.huihui</groupId>
<artifactId>answerit</artifactId>
<version>1.53-SNAPSHOT</version>
<version>1.54-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Answerit</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package top.mpt.huihui.answerit.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import top.mpt.huihui.answerit.prize.prize;
import top.mpt.huihui.answerit.utils.ChatUtils;
import top.mpt.huihui.answerit.utils.i18N;

import static top.mpt.huihui.answerit.Main.Online_Players;
import static top.mpt.huihui.answerit.Main.playersOnQuestioning;

public class PlayerJoinAndQuit implements Listener {
@EventHandler
Expand All @@ -17,7 +23,15 @@ public void onPlayerJoin(PlayerJoinEvent event){

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event){
String PlayerName = event.getPlayer().getName();
Online_Players.remove(PlayerName);
Player player = event.getPlayer();
Online_Players.remove(player.getName());
// 如果玩家在提问队列中,就移除玩家
// TODO:并扣除生命值上限
if (playersOnQuestioning.contains(player)){
playersOnQuestioning.remove(prize.getPrizePlayer());
playersOnQuestioning.remove(prize.getTargetPlayer());
// 全服公告
ChatUtils.broadcast(i18N.getLang("global.player_quit").toString(), player.getName());
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/top/mpt/huihui/answerit/prize/prize.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public static void executePrize(){
playersOnQuestioning.remove(targetPlayer);
clearAllPlayer();
}
// // 判断玩家是否被减少了生命值,如果被减少过,就设置玩家生命值为正常值
// else if (prizePlayer.isHealthScaled()){
// prizePlayer.setHealthScale(20);
// prizePlayer.setHealthScaled(false);
// }
else {
// 执行奖励
prizePlayer.openInventory(targetPlayer.getInventory());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ global:
player_cant_answer: "#RED#You cannot answer it again!!!"
command_err_format: "#AQUA#The format you entered is incorrect!"
inv_closed: "#AQUA#This Q&A operation has ended."
player_quit: "#RED#Player: #AQUA#%s #RED#quited the game during the Q&A operation, so the Q&A operation has ended."

select:
player_send_question: "#AQUA#The target has received your question, please be patient and wait for his or her answer."
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ global:
player_cant_answer: "#RED#想啥呢?答完题了还想再答是吧???给爷爬!!!"
command_err_format: "#AQUA#您输入的格式并不正确!"
inv_closed: "#AQUA#本次问答操作已结束。"
player_quit: "#RED#玩家: #AQUA#%s#RED#在问答过程中陶艺了,本次问答操作已结束。"

select:
player_send_question: "#AQUA#对方已收到您的问题,请耐心等待对方回答。"
Expand Down

0 comments on commit 93dfc0d

Please sign in to comment.