Skip to content

Commit

Permalink
完成了 i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Sep 5, 2024
1 parent f2c04df commit 16728cc
Show file tree
Hide file tree
Showing 20 changed files with 868 additions and 257 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "cn.lunadeer"
version = "2.5.6-beta"
version = "2.5.7-beta"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/cn/lunadeer/dominion/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
case "export_mca":
Operator.exportMca(sender, args);
break;
case "sys_config":
SysConfig.show(sender, args);
break;
case "set_config":
SetConfig.handler(sender, args);
break;
// case "set_config":
// SetConfig.handler(sender, args);
// break;
case "all_dominion":
AllDominion.show(sender, args);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.tuis.SysConfig;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;

import static cn.lunadeer.dominion.utils.CommandUtils.hasPermission;

public class SetConfig {

@Deprecated
public static void handler(CommandSender sender, String[] args) {
if (!hasPermission(sender, "dominion.admin")) {
return;
Expand Down Expand Up @@ -87,7 +87,7 @@ public static void refreshPageOrNot(CommandSender sender, String[] args) {
String[] newArgs = new String[2];
newArgs[0] = "config";
newArgs[1] = String.valueOf(page);
SysConfig.show(sender, newArgs);
// SysConfig.show(sender, newArgs);
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static List<DominionDTO> query(String sql, Object... args) {
try (ResultSet rs = DatabaseManager.instance.query(sql, args)) {
return getDTOFromRS(rs);
} catch (SQLException e) {
DatabaseManager.handleDatabaseError("数据库操作失败: ", e, sql);
DatabaseManager.handleDatabaseError("DominionDTO.query ", e, sql);
}
return dominions;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public static DominionDTO insert(DominionDTO dominion) {
if (dominions.isEmpty()) return null;
return dominions.getFirst();
} catch (SQLException e) {
DatabaseManager.handleDatabaseError("数据库操作失败: ", e, insert.toString());
DatabaseManager.handleDatabaseError("DominionDTO.insert ", e, insert.toString());
return null;
}
}
Expand Down Expand Up @@ -234,7 +234,7 @@ private DominionDTO doUpdate(UpdateRow updateRow) {
Cache.instance.loadDominions((Integer) id.value);
return dominions.getFirst();
} catch (SQLException e) {
DatabaseManager.handleDatabaseError("更新领地信息失败: ", e, updateRow.toString());
DatabaseManager.handleDatabaseError("DominionDTO.doUpdate ", e, updateRow.toString());
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cn/lunadeer/dominion/dtos/GroupDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static GroupDTO create(String name, DominionDTO dominionDTO) {
Cache.instance.loadGroups(groups.getFirst().getId());
return groups.getFirst();
} catch (Exception e) {
DatabaseManager.handleDatabaseError("创建权限组失败: ", e, "");
DatabaseManager.handleDatabaseError("GroupDTO.create ", e, "");
return null;
}
}
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/java/cn/lunadeer/dominion/dtos/MemberDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private static List<MemberDTO> query(String sql, Object... params) {
try (ResultSet rs = DatabaseManager.instance.query(sql, params)) {
return getDTOFromRS(rs);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询玩家权限失败: ", e, sql);
DatabaseManager.handleDatabaseError("MemberDTO.query ", e, sql);
}
return players;
}
Expand All @@ -42,7 +42,7 @@ private static List<MemberDTO> getDTOFromRS(ResultSet rs) {
players.add(player);
}
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询玩家权限失败: ", e, "");
DatabaseManager.handleDatabaseError("MemberDTO.getDTOFromRS ", e, "");
}
return players;
}
Expand All @@ -53,11 +53,11 @@ private MemberDTO doUpdate(UpdateRow updateRow) {
.where("id = ?", id.value);
try (ResultSet rs = updateRow.execute()) {
List<MemberDTO> players = getDTOFromRS(rs);
if (players.size() == 0) return null;
if (players.isEmpty()) return null;
Cache.instance.loadMembers(getPlayerUUID());
return players.get(0);
return players.getFirst();
} catch (Exception e) {
DatabaseManager.handleDatabaseError("更新玩家权限失败: ", e, "");
DatabaseManager.handleDatabaseError("MemberDTO.doUpdate ", e, "");
return null;
}
}
Expand All @@ -74,19 +74,19 @@ public static MemberDTO insert(MemberDTO player) {
try (ResultSet rs = insertRow.execute()) {
Cache.instance.loadMembers(player.getPlayerUUID());
List<MemberDTO> players = getDTOFromRS(rs);
if (players.size() == 0) return null;
return players.get(0);
if (players.isEmpty()) return null;
return players.getFirst();
} catch (Exception e) {
DatabaseManager.handleDatabaseError("插入玩家权限失败: ", e, "");
DatabaseManager.handleDatabaseError("MemberDTO.insert ", e, "");
return null;
}
}

public static MemberDTO select(UUID playerUUID, Integer dom_id) {
String sql = "SELECT * FROM dominion_member WHERE player_uuid = ? AND dom_id = ?;";
List<MemberDTO> p = query(sql, playerUUID.toString(), dom_id);
if (p.size() == 0) return null;
return p.get(0);
if (p.isEmpty()) return null;
return p.getFirst();
}

public static List<MemberDTO> select(Integer dom_id) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static List<PlayerDTO> query(String sql, Object... params) {
try (ResultSet rs = DatabaseManager.instance.query(sql, params)) {
return getDTOFromRS(rs);
} catch (SQLException e) {
DatabaseManager.handleDatabaseError("查询玩家信息失败: ", e, sql);
DatabaseManager.handleDatabaseError("PlayerDTO.query ", e, sql);
}
return players;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ private static PlayerDTO insert(PlayerDTO player) {
if (players.isEmpty()) return null;
return players.getFirst();
} catch (SQLException e) {
DatabaseManager.handleDatabaseError("插入玩家信息失败: ", e, insertRow.toString());
DatabaseManager.handleDatabaseError("PlayerDTO.insert ", e, insertRow.toString());
return null;
}
}
Expand All @@ -138,7 +138,7 @@ private static PlayerDTO update(PlayerDTO player) {
if (players.isEmpty()) return null;
return players.getFirst();
} catch (SQLException e) {
DatabaseManager.handleDatabaseError("更新玩家信息失败: ", e, updateRow.toString());
DatabaseManager.handleDatabaseError("PlayerDTO.update ", e, updateRow.toString());
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private static List<PrivilegeTemplateDTO> query(String sql, Object... params) {
try (ResultSet rs = DatabaseManager.instance.query(sql, params)) {
return getDTOFromRS(rs);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询权限模版失败: ", e, sql);
DatabaseManager.handleDatabaseError("PrivilegeTemplateDTO.query ", e, sql);
}
return templates;
}
Expand All @@ -39,7 +39,7 @@ private static List<PrivilegeTemplateDTO> getDTOFromRS(ResultSet rs) {
templates.add(template);
}
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询权限模版失败: ", e, null);
DatabaseManager.handleDatabaseError("PrivilegeTemplateDTO.getDTOFromRS", e, null);
}
return templates;
}
Expand All @@ -53,10 +53,10 @@ public static PrivilegeTemplateDTO create(UUID creator, String name) {
.returningAll();
try (ResultSet rs = insertRow.execute()) {
List<PrivilegeTemplateDTO> templates = getDTOFromRS(rs);
if (templates.size() == 0) return null;
return templates.get(0);
if (templates.isEmpty()) return null;
return templates.getFirst();
} catch (Exception e) {
DatabaseManager.handleDatabaseError("创建权限模版失败: ", e, null);
DatabaseManager.handleDatabaseError("PrivilegeTemplateDTO.create ", e, null);
return null;
}
}
Expand All @@ -68,19 +68,19 @@ private PrivilegeTemplateDTO doUpdate(UpdateRow updateRow) {
.where("id = ?", id.value);
try (ResultSet rs = updateRow.execute()) {
List<PrivilegeTemplateDTO> templates = getDTOFromRS(rs);
if (templates.size() == 0) return null;
return templates.get(0);
if (templates.isEmpty()) return null;
return templates.getFirst();
} catch (Exception e) {
DatabaseManager.handleDatabaseError("更新权限模版失败: ", e, null);
DatabaseManager.handleDatabaseError("PrivilegeTemplateDTO.doUpdate ", e, null);
return null;
}
}

public static PrivilegeTemplateDTO select(UUID creator, String name) {
String sql = "SELECT * FROM privilege_template WHERE creator = ? AND name = ?;";
List<PrivilegeTemplateDTO> templates = query(sql, creator.toString(), name);
if (templates.size() == 0) return null;
return templates.get(0);
if (templates.isEmpty()) return null;
return templates.getFirst();
}

public static List<PrivilegeTemplateDTO> selectAll(UUID creator) {
Expand All @@ -101,9 +101,9 @@ private PrivilegeTemplateDTO(Integer id, UUID creator, String name, Boolean admi
this.flags.putAll(flags);
}

private Integer id;
private UUID creator;
private String name;
private final Integer id;
private final UUID creator;
private final String name;
private Boolean admin;

private final Map<Flag, Boolean> flags = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public ConfigManager(Dominion plugin) {
_plugin = plugin;
_plugin.saveDefaultConfig();
reload();
_plugin.saveConfig();
}

public void reload() {
Expand Down Expand Up @@ -55,7 +54,15 @@ public void reload() {
_check_update = _file.getBoolean("CheckUpdate", true);
_tp_enable = _file.getBoolean("Teleport.Enable", false);
_tp_delay = _file.getInt("Teleport.Delay", 0);
if (_tp_delay < 0) {
XLogger.err(Translation.Config_Check_TpDelayError);
setTpDelay(0);
}
_tp_cool_down = _file.getInt("Teleport.CoolDown", 0);
if (_tp_cool_down < 0) {
XLogger.err(Translation.Config_Check_TpCoolDownError);
setTpCoolDown(0);
}
_tool = _file.getString("Tool", "ARROW");
if (Material.getMaterial(_tool) == null) {
XLogger.err(Translation.Config_Check_ToolNameError);
Expand Down Expand Up @@ -84,6 +91,8 @@ public void reload() {
defaultGroup.setPrice(_file.getDouble("Economy.Price", 10.0));
defaultGroup.setPriceOnlyXZ(_file.getBoolean("Economy.OnlyXZ", false));
defaultGroup.setRefundRatio(_file.getDouble("Economy.Refund", 0.85));
limits.put("default", defaultGroup);

if (defaultGroup.getLimitSizeX() <= 4 && defaultGroup.getLimitSizeX() != -1) {
XLogger.err(Translation.Config_Check_LimitSizeXError);
setLimitSizeX(128);
Expand Down Expand Up @@ -121,7 +130,6 @@ public void reload() {
XLogger.err(Translation.Config_Check_DepthError);
setLimitDepth(3);
}
limits.put("default", defaultGroup);

limits.putAll(GroupLimit.loadGroups(_plugin));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ public class Translation extends Localization {
public static i18n Messages_SetDominionFlagSuccess;
@i18nField(defaultValue = "未知的权限 %s")
public static i18n Messages_UnknownFlag;
@i18nField(defaultValue = "你没有权限访问此页面")
public static i18n Messages_PageNoPermission;

@i18nField(defaultValue = "创建权限组 %s 失败")
public static i18n Messages_CreateGroupFailed;
Expand Down Expand Up @@ -535,6 +537,16 @@ public class Translation extends Localization {
public static i18n TUI_Navigation_GroupList;
@i18nField(defaultValue = "权限组管理")
public static i18n TUI_Navigation_GroupSetting;
@i18nField(defaultValue = "所有领地")
public static i18n TUI_Navigation_AllDominion;
@i18nField(defaultValue = "模板列表")
public static i18n TUI_Navigation_TemplateList;
@i18nField(defaultValue = "模板管理")
public static i18n TUI_Navigation_TemplateSetting;
@i18nField(defaultValue = "Res数据列表")
public static i18n TUI_Navigation_MigrateList;
@i18nField(defaultValue = "权限组称号列表")
public static i18n TUI_Navigation_TitleList;

@i18nField(defaultValue = "管理")
public static i18n TUI_ManageButton;
Expand Down Expand Up @@ -733,7 +745,7 @@ public class Translation extends Localization {
@i18nField(defaultValue = "用法: /dominion member select_template <领地名称> <玩家名称> [页码]")
public static i18n TUI_SelectTemplate_Usage;

@i18nField(defaultValue = "权限组列表")
@i18nField(defaultValue = "领地 %s 权限组列表")
public static i18n TUI_GroupList_Title;
@i18nField(defaultValue = "创建权限组")
public static i18n TUI_GroupList_CreateButton;
Expand Down Expand Up @@ -768,6 +780,37 @@ public class Translation extends Localization {
@i18nField(defaultValue = "用法: /dominion group select_member <领地名称> <权限组名称> [回显页码] [页码]")
public static i18n TUI_SelectMember_Usage;

@i18nField(defaultValue = "成员权限模板列表")
public static i18n TUI_TemplateList_Title;
@i18nField(defaultValue = "创建成员权限模板")
public static i18n TUI_TemplateList_CreateButton;
@i18nField(defaultValue = "创建一个新的成员权限模板")
public static i18n TUI_TemplateList_CreateDescription;

@i18nField(defaultValue = "模板 %s 权限管理")
public static i18n TUI_TemplateSetting_Title;

@i18nField(defaultValue = "从 Residence 迁移数据")
public static i18n TUI_Migrate_Title;
@i18nField(defaultValue = "你没有可迁移的数据")
public static i18n TUI_Migrate_NoData;
@i18nField(defaultValue = "迁移")
public static i18n TUI_Migrate_Button;
@i18nField(defaultValue = "子领地无法手动迁移,会随父领地自动迁移")
public static i18n TUI_Migrate_SubDominion;

@i18nField(defaultValue = "我可使用的权限组称号")
public static i18n TUI_TitleList_Title;
@i18nField(defaultValue = "卸下")
public static i18n TUI_TitleList_RemoveButton;
@i18nField(defaultValue = "使用")
public static i18n TUI_TitleList_ApplyButton;
@i18nField(defaultValue = "来自领地:")
public static i18n TUI_TitleList_FromDominion;

@i18nField(defaultValue = "Dominion 系统配置")
public static i18n TUI_Config_Title;

@i18nField(defaultValue = "输入要创建的领地名称")
public static i18n CUI_Input_CreateDominion;
@i18nField(defaultValue = "输入要创建的权限组名称")
Expand Down Expand Up @@ -829,6 +872,10 @@ public class Translation extends Localization {
public static i18n Config_Check_GroupRefundError;
@i18nField(defaultValue = "读取权限配置失败:%s")
public static i18n Config_Check_LoadFlagError;
@i18nField(defaultValue = "传送延迟不能小于 0,已重置为 0")
public static i18n Config_Check_TpDelayError;
@i18nField(defaultValue = "传送冷却不能小于 0,已重置为 0")
public static i18n Config_Check_TpCoolDownError;

@i18nField(defaultValue = "语言设置,参考 languages 文件夹下的文件名")
public static i18n Config_Comment_Language;
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/cn/lunadeer/dominion/tuis/AllDominion.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.lunadeer.dominion.DominionNode;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
Expand All @@ -27,8 +28,8 @@ public static void show(CommandSender sender, String[] args) {

ListView view = ListView.create(10, "/dominion all_dominion");

view.title("所有领地");
view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("所有领地"));
view.title(Translation.TUI_Navigation_AllDominion);
view.navigator(Line.create().append(Button.create(Translation.TUI_Navigation_Menu).setExecuteCommand("/dominion menu").build()).append((Translation.TUI_Navigation_AllDominion)));
view.addLines(BuildTreeLines(allDominions, 0));
view.showOn(player, page);
}
Expand Down
Loading

0 comments on commit 16728cc

Please sign in to comment.