Skip to content

Commit 7d8bbaf

Browse files
Debug Added & Bug/Grammar Fix
1 parent 674c28a commit 7d8bbaf

File tree

7 files changed

+82
-8
lines changed

7 files changed

+82
-8
lines changed

src/main/java/top/mpt/huihui/answerit/Main.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package top.mpt.huihui.answerit;
22

3+
import org.bukkit.Bukkit;
34
import org.bukkit.ChatColor;
45
import org.bukkit.configuration.file.FileConfiguration;
56
import org.bukkit.configuration.file.YamlConfiguration;
7+
import org.bukkit.entity.Player;
68
import org.bukkit.plugin.java.JavaPlugin;
79
import top.mpt.huihui.answerit.executor.CommandHandler;
810
import top.mpt.huihui.answerit.listener.InvOpen;
911
import top.mpt.huihui.answerit.listener.PlayerChat;
12+
import top.mpt.huihui.answerit.listener.PlayerJoinAndQuit;
1013
import top.mpt.huihui.answerit.utils.i18N;
1114

1215
import java.io.*;
13-
import java.util.ArrayList;
14-
import java.util.List;
16+
import java.util.*;
1517

1618
import static org.bukkit.ChatColor.BLUE;
1719

@@ -30,6 +32,8 @@ public final class Main extends JavaPlugin {
3032
public static boolean canVote = false;
3133
// 用于lang sys
3234
public static FileConfiguration config;
35+
// 新建数组,存放玩家,会在PlayerJoinAndQuit类和q类中被调用
36+
public static List<String> Online_Players = new ArrayList<>();
3337
// 设置normal项(用于broadcast)
3438
public static String normal = BLUE + "[AnswerIt] ";
3539
@Override
@@ -38,6 +42,10 @@ public void onEnable() {
3842
// config
3943
getConfig().options().copyDefaults();
4044
saveDefaultConfig();
45+
46+
47+
48+
4149
File file = new File(getDataFolder() + "/lang/", getConfig().getString("lang"));
4250
saveResource("lang/zh_cn.yml", false);
4351
saveResource("lang/en_us.yml", false);
@@ -49,6 +57,7 @@ public void onEnable() {
4957
// 注册事件
5058
getServer().getPluginManager().registerEvents(new PlayerChat(), this);
5159
getServer().getPluginManager().registerEvents(new InvOpen(), this);
60+
getServer().getPluginManager().registerEvents(new PlayerJoinAndQuit(), this);
5261
getLogger().info(normal + ChatColor.AQUA + "Plugin Enabled");
5362
/* wait player's commands */
5463
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package top.mpt.huihui.answerit.commands.impl;
2+
3+
import org.bukkit.ChatColor;
4+
import org.bukkit.command.CommandSender;
5+
import top.mpt.huihui.answerit.commands.ICommand;
6+
import top.mpt.huihui.answerit.utils.PlayerUtils;
7+
import top.mpt.huihui.answerit.utils.i18N;
8+
9+
import static top.mpt.huihui.answerit.Main.Online_Players;
10+
11+
public class debug extends ICommand {
12+
public debug(){
13+
super("debug", "", "/answer debug [language_path_single]/getOnline");
14+
}
15+
16+
public boolean onCommand(CommandSender sender, String[] args) {
17+
if (args.length < 1){
18+
sender.sendMessage(ChatColor.RED + "Error args");
19+
return true;
20+
}
21+
if (args[0].equals("getOnline")){
22+
sender.sendMessage(ChatColor.AQUA + "Online Players:" + Online_Players);
23+
}
24+
else {
25+
PlayerUtils.send(sender, i18N.getLang(args[0]));
26+
}
27+
return true;
28+
}
29+
30+
public String permission() {
31+
return "answerop.debug";
32+
}
33+
}

src/main/java/top/mpt/huihui/answerit/commands/impl/reload.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.mpt.huihui.answerit.commands.impl;
22

3+
import org.bukkit.Bukkit;
34
import org.bukkit.command.CommandSender;
45
import org.bukkit.configuration.file.YamlConfiguration;
56
import org.bukkit.plugin.java.JavaPlugin;
@@ -22,6 +23,10 @@ public boolean onCommand(CommandSender sender, String[] args) {
2223
File file = new File(main.getDataFolder() + "/lang/", main.getConfig().getString("lang"));
2324
config = YamlConfiguration.loadConfiguration(file);
2425
i18N.setYaml(config);
26+
27+
Online_Players.clear();
28+
Bukkit.getOnlinePlayers().forEach( it -> Online_Players.add(it.getName()) );
29+
2530
sender.sendMessage("[AnswerIt] Plugin Reload Completed");
2631
return true;
2732
}

src/main/java/top/mpt/huihui/answerit/executor/CommandHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private void initHandler() {
3434
registerCommand(new q());
3535
registerCommand(new send());
3636
registerCommand(new vote());
37+
registerCommand(new debug());
3738
registerCommand(new reload());
3839
registerCommand(new setAnswer());
3940

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package top.mpt.huihui.answerit.listener;
2+
3+
import org.bukkit.event.EventHandler;
4+
import org.bukkit.event.Listener;
5+
import org.bukkit.event.player.PlayerJoinEvent;
6+
import org.bukkit.event.player.PlayerQuitEvent;
7+
import static top.mpt.huihui.answerit.Main.Online_Players;
8+
9+
public class PlayerJoinAndQuit implements Listener {
10+
@EventHandler
11+
public void onPlayerJoin(PlayerJoinEvent event){
12+
String PlayerName = event.getPlayer().getName();
13+
if (!Online_Players.contains(PlayerName)){
14+
Online_Players.add(PlayerName);
15+
}
16+
}
17+
18+
@EventHandler
19+
public void onPlayerQuit(PlayerQuitEvent event){
20+
String PlayerName = event.getPlayer().getName();
21+
Online_Players.remove(PlayerName);
22+
}
23+
}

src/main/resources/lang/en_us.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# In this file, player refers to the questioner and target refers to the respondent
22
# PS. the color code (such as #AQUA#) can modify the color in org.bukkit.ChatColor
3-
# Please do not modify the placeholder (such as %s & %d)
3+
# DO NOT MODIFY THE PLACEHOLDERS (such as %s & %d)
44
# DO NOT DELETE ANY SPACES IN QUOTATION MARK
55

6-
sender_err: "Please let the player to execute the command!"
6+
sender_err: "Please let players execute this command!"
77
mode_err: "#RED#Mode is wrong, please ask %s to check about."
88
player_err: "#RED#Cannot find players who named that. Or maybe the player isn't online."
99

@@ -32,8 +32,8 @@ write:
3232
player_cant_vote: "#RED#You have already voted, please do not vote again!"
3333
vote_timeout: "#RED#Voting time out."
3434
# please don't delete space
35-
vote_right: "#GREEN#[Correct] "
36-
vote_wrong: "#RED#[Incorrect]"
35+
vote_right: "#GREEN#[RIGHT] "
36+
vote_wrong: "#RED#[WRONG]"
3737
# broadcast_info
3838
server_vote_right_info: "#GREEN#Player: #AQUA#%s #GREEN#vote for Correct"
3939
server_vote_wrong_info: "#GREEN#Player: #AQUA#%s #GREEN#vote for Incorrect"
@@ -45,7 +45,7 @@ timer:
4545
timer_start_info: "#RED#Timing #AQUA#%d #RED#seconds, now start"
4646
timer_start_tip: "#RED#Please complete the voting within the specified time."
4747

48-
timer_over_summary: "#GREEN#Vote closed. %d players vote for Correct,%d vote for Incorrect"
49-
votes_equal: "#GOLD#Equal votes, no reward or punishment"
48+
timer_over_summary: "#GREEN#Vote closed. %d players vote for RIGHT,%d vote for WRONG"
49+
votes_equal: "#GOLD#Equal votes, no reward or punishment for them."
5050
votes_right: "#GREEN#Answer correct!"
5151
votes_wrong: "#RED#Answer Incorrect!"

src/main/resources/plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ permissions:
1616
default: true
1717
answerop.reload:
1818
description: op command
19+
default: op
20+
answerop.debug:
21+
description: developer command
1922
default: op

0 commit comments

Comments
 (0)