Skip to content

Commit

Permalink
添加AutomaticJoinGame配置
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Aug 6, 2023
1 parent 6f4f930 commit 4227506
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/main/java/cn/lanink/murdermystery/MurderMystery.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.lanink.gamecore.GameCore;
import cn.lanink.gamecore.scoreboard.ScoreboardUtil;
import cn.lanink.gamecore.scoreboard.base.IScoreboard;
import cn.lanink.gamecore.utils.ConfigUtils;
import cn.lanink.gamecore.utils.FileUtils;
import cn.lanink.gamecore.utils.Language;
import cn.lanink.gamecore.utils.VersionUtils;
Expand All @@ -26,6 +27,7 @@
import cn.lanink.murdermystery.tasks.admin.SetRoomTask;
import cn.lanink.murdermystery.utils.MetricsLite;
import cn.lanink.murdermystery.utils.RsNpcVariable;
import cn.lanink.murdermystery.utils.update.ConfigUpdateUtils;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.entity.data.Skin;
Expand Down Expand Up @@ -101,6 +103,9 @@ public class MurderMystery extends PluginBase {

private boolean restoreWorld = false;
private boolean autoCreateTemporaryRoom = false;

@Getter
private boolean automaticJoinGame = false;
@Getter
private boolean automaticNextRound = false; //游戏结束后自动加入新房间

Expand Down Expand Up @@ -154,12 +159,20 @@ public void onLoad() {
}
}

ConfigUpdateUtils.updateConfig();
Config configDescription = new Config();
configDescription.load(this.getResource("Resources/Language/ConfigDescription/" + this.config.getString("language", "zh_CN") + ".yml"));
ConfigUtils.addDescription(this.config, configDescription);

this.config = new Config(this.getDataFolder() + "/config.yml", Config.YAML);

this.temporaryRoomsConfig = new Config(this.getDataFolder() + "/temporaryRoomList.yml", Config.YAML);
this.temporaryRooms = new CopyOnWriteArrayList<>(this.temporaryRoomsConfig.getStringList("temporaryRooms"));
this.removeAllTemporaryRoom();

this.restoreWorld = this.config.getBoolean("restoreWorld", false);
this.autoCreateTemporaryRoom = this.config.getBoolean("autoCreateTemporaryRoom", false);
this.automaticJoinGame = this.config.getBoolean("AutomaticJoinGame", false);
this.automaticNextRound = this.config.getBoolean("AutomaticNextRound", false);

this.cmdUser = this.config.getString("cmdUser", "murdermystery");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerJoinEvent;
import cn.nukkit.event.player.PlayerLocallyInitializedEvent;
import cn.nukkit.event.player.PlayerQuitEvent;
import cn.nukkit.event.player.PlayerTeleportEvent;

Expand Down Expand Up @@ -57,6 +58,17 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
}

@EventHandler
public void onPlayerLocallyInitialized(PlayerLocallyInitializedEvent event) {
Player player = event.getPlayer();
if (player == null) {
return;
}
if (this.murderMystery.isAutomaticJoinGame()) {
Server.getInstance().dispatchCommand(player, this.murderMystery.getCmdUser() + " join");
}
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cn.lanink.murdermystery.utils.update;

import cn.lanink.gamecore.utils.VersionUtils;
import cn.lanink.murdermystery.MurderMystery;
import cn.nukkit.utils.Config;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

/**
* @author LT_Name
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ConfigUpdateUtils {

public static void updateConfig() {
update1_X_X_To_1_4_2();
}

@NotNull
private static Config getConfig() {
return new Config(MurderMystery.getInstance().getDataFolder() + "/config.yml", Config.YAML);
}

private static void update1_X_X_To_1_4_2() {
Config config = getConfig();
if (VersionUtils.compareVersion(config.getString("ConfigVersion", "1.0.0"), "1.4.2") >= 0) {
return;
}

config.set("ConfigVersion", "1.4.2");

if (!config.exists("AutomaticJoinGame")) {
config.set("AutomaticJoinGame", false);
}

config.save();
}

}
32 changes: 32 additions & 0 deletions src/main/resources/Resources/Language/ConfigDescription/zh_CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
header: |-
MurderMystery 插件配置文件
footer: |-
你已经到达配置文件的底部啦
ConfigVersion: |-
配置文件的版本号
警告! 除非您明确知道您在干什么,否则不要尝试改动此项配置!
defaultLanguage: "插件默认语言设置 可选 zh_CN | en_US | ko_KR | vi_VN | de_DE"
languageMappingTable: "语言映射表"
autoUpdateLanguage: "自动更新语言文件"

cmdUser: "插件命令"
cmdUserAliases: "插件命令别名"
cmdAdmin: "插件管理命令"
cmdAdminAliases: "插件管理命令别名"
cmdWhitelist: "可以在游戏房间中使用的命令"

restoreWorld: |-
结束游戏后还原地图
注意:仅在首次加载房间时备份地图!
autoCreateTemporaryRoom: "自动创建临时房间 保证至少有一个空闲房间"

AutomaticJoinGame: "玩家进入服务器后自动加入游戏房间(适用于群组服游戏子服场景)"
QuitRoom.cmd: "退出房间执行命令"
AutomaticNextRound: "游戏结束后自动加入下一局 (建议开启autoCreateTemporaryRoom)"

killerVictoryCmd: "杀手胜利执行命令(仅杀手执行)"
commonPeopleVictoryCmd: "平民与侦探胜利执行命令(仅存活的玩家执行)"
killKillerCmd: "击杀杀手的玩家执行命令"
defeatCmd: "失败执行命令"
22 changes: 14 additions & 8 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ConfigVersion: 1.4.2

#zh_CN | en_US | ko_KR | vi_VN | de_DE
defaultLanguage: zh_CN
languageMappingTable:
Expand All @@ -9,14 +11,7 @@ languageMappingTable:
en_GB: "en_US"
de: "de_DE"
autoUpdateLanguage: false
#结束游戏后还原地图
#注意:仅在首次加载房间时备份地图!
#Restore the map(world) after the game is over
#Note: The map(world) is only backed up when loading the room for the first time!
restoreWorld: true
#自动创建临时房间 保证至少有一个空闲房间
#Automatically create a temporary room to ensure that there is at least one free room
autoCreateTemporaryRoom: true

#插件命令 Plugin commands
cmdUser: murdermystery
cmdUserAliases:
Expand All @@ -30,6 +25,17 @@ cmdWhitelist:
- kick
- report

#结束游戏后还原地图
#注意:仅在首次加载房间时备份地图!
#Restore the map(world) after the game is over
#Note: The map(world) is only backed up when loading the room for the first time!
restoreWorld: true
#自动创建临时房间 保证至少有一个空闲房间
#Automatically create a temporary room to ensure that there is at least one free room
autoCreateTemporaryRoom: true

#玩家进入服务器后自动加入游戏房间(适用于群组服游戏子服场景)
AutomaticJoinGame: false
QuitRoom:
#退出房间执行命令
cmd: []
Expand Down

0 comments on commit 4227506

Please sign in to comment.