完成了 DominionController i18n

This commit is contained in:
zhangyuheng 2024-09-03 00:45:23 +08:00
parent 7c09f09a85
commit 8773fd35d2
3 changed files with 241 additions and 90 deletions

View File

@ -1,5 +1,6 @@
package cn.lunadeer.dominion.controllers;
import cn.lunadeer.minecraftpluginutils.i18n.i18n;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
@ -20,6 +21,12 @@ public interface AbstractOperator {
private Integer success;
private List<String> messages;
public Result(Integer success, i18n message, Object... args) {
this.success = success;
this.messages = new ArrayList<>();
this.messages.add(message.trans());
}
public Result(Integer success, String message, Object... args) {
this.success = success;
this.messages = new ArrayList<>();
@ -31,6 +38,10 @@ public interface AbstractOperator {
return this;
}
public Result addMessage(i18n message, Object... args) {
return addMessage(message.trans(), args);
}
public Integer getStatus() {
return success;
}

View File

@ -4,6 +4,7 @@ import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.Particle;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
@ -84,32 +85,32 @@ public class DominionController {
public static void create(AbstractOperator operator, String name,
Location loc1, Location loc2,
@NotNull String parent_dominion_name, boolean skipEco) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建领地失败");
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功创建领地 %s", name);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_CreateDominionFailed);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_CreateDominionSuccess, name);
if (name.isEmpty()) {
operator.setResponse(FAIL.addMessage("领地名称不能为空"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNameShouldNotEmpty));
return;
}
if (name.contains(" ") || name.contains(".")) {
operator.setResponse(FAIL.addMessage("领地名称不能包含空格或点"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNameInvalid));
return;
}
if (DominionDTO.select(name) != null) {
operator.setResponse(FAIL.addMessage("已经存在名称为 %s 的领地", name));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNameExist, name));
return;
}
if (!loc1.getWorld().getUID().equals(loc2.getWorld().getUID())) {
operator.setResponse(FAIL.addMessage("选点世界不一致"));
operator.setResponse(FAIL.addMessage(Translation.Controller_SelectPointsWorldNotSame));
return;
}
// 检查世界是否可以创建
if (worldNotValid(operator, loc1.getWorld().getName())) {
operator.setResponse(FAIL.addMessage("禁止在世界 %s 创建领地", loc1.getWorld().getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_CreateDominionDisabledWorld, loc1.getWorld().getName()));
return;
}
// 检查领地数量是否达到上限
if (amountNotValid(operator)) {
operator.setResponse(FAIL.addMessage("你的领地数量已达上限(%d个)", Dominion.config.getLimitAmount(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionAmountLimit, Dominion.config.getLimitAmount(operator.getPlayer())));
return;
}
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
@ -129,16 +130,16 @@ public class DominionController {
parent_dominion = DominionDTO.select(parent_dominion_name);
}
if (parent_dominion == null) {
operator.setResponse(FAIL.addMessage("父领地 %s 不存在", parent_dominion_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_ParentDominionNotExist, parent_dominion_name));
if (parent_dominion_name.isEmpty()) {
XLogger.err("根领地丢失!");
XLogger.err(Translation.Controller_RootDominionLost);
}
return;
}
// 是否是父领地的拥有者
if (parent_dominion.getId() != -1) {
if (notOwner(operator, parent_dominion)) {
operator.setResponse(FAIL.addMessage("你不是父领地 %s 的拥有者,无法创建子领地", parent_dominion_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotParentDominionOwner, parent_dominion_name));
return;
}
}
@ -147,7 +148,7 @@ public class DominionController {
minX, minY, minZ, maxX, maxY, maxZ, parent_dominion);
// 如果parent_dominion不为-1 检查是否在同一世界
if (parent_dominion.getId() != -1 && !parent_dominion.getWorldUid().equals(dominion.getWorldUid())) {
operator.setResponse(FAIL.addMessage("父领地与子领地不在同一世界。"));
operator.setResponse(FAIL.addMessage(Translation.Controller_ParentDominionNotInSameWorld));
return;
}
// 检查深度是否达到上限
@ -156,20 +157,20 @@ public class DominionController {
}
// 检查是否超出父领地范围
if (!isContained(dominion, parent_dominion)) {
operator.setResponse(FAIL.addMessage("超出父领地 %s 范围", parent_dominion.getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_OutOfParentDominionRange, parent_dominion.getName()));
return;
}
// 获取此领地的所有同级领地
List<DominionDTO> sub_dominions = DominionDTO.selectByParentId(dominion.getWorldUid(), parent_dominion.getId());
// 检查是否与出生点保护冲突
if (isIntersectSpawn(operator, dominion)) {
operator.setResponse(FAIL.addMessage("与出生点保护冲突"));
operator.setResponse(FAIL.addMessage(Translation.Controller_ConflictWithSpawnProtect));
return;
}
// 检查是否与其他子领地冲突
for (DominionDTO sub_dominion : sub_dominions) {
if (isIntersect(sub_dominion, dominion)) {
operator.setResponse(FAIL.addMessage("与领地 %s 冲突", sub_dominion.getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_ConflictWithDominion, sub_dominion.getName()));
return;
}
}
@ -181,7 +182,7 @@ public class DominionController {
}
dominion = DominionDTO.insert(dominion);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("创建领地失败,数据库错误,请联系管理员"));
operator.setResponse(FAIL.addMessage(Translation.Controller_CreateDominionDatabaseError));
return;
}
// 显示粒子效果
@ -230,7 +231,7 @@ public class DominionController {
public static void expand(AbstractOperator operator, Integer size) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你所处的领地,请指定名称"));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_CannotGetDominionAuto));
return;
}
expand(operator, size, dominion.getName());
@ -244,7 +245,7 @@ public class DominionController {
* @param dominion_name 领地名称
*/
public static void expand(AbstractOperator operator, Integer size, String dominion_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "扩展领地失败");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_ExpandDominionFailed);
DominionDTO dominion = expandContractPreCheck(operator, getExistDomAndIsOwner(operator, dominion_name), FAIL);
if (dominion == null) {
return;
@ -254,18 +255,23 @@ public class DominionController {
return;
}
// 检查是否与出生点保护冲突
if (isIntersectSpawn(operator, dominion.getWorld(), newCords)) {
operator.setResponse(FAIL.addMessage("与出生点保护冲突"));
World world = Dominion.instance.getServer().getWorld(dominion.getWorldUid());
if (world == null) {
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionWorldLost));
return;
}
if (isIntersectSpawn(operator, world, newCords)) {
operator.setResponse(FAIL.addMessage(Translation.Controller_ConflictWithSpawnProtect));
return;
}
// 校验是否超出父领地范围
DominionDTO parent_dominion = DominionDTO.select(dominion.getParentDomId());
if (parent_dominion == null) {
operator.setResponse(FAIL.addMessage("父领地丢失"));
operator.setResponse(FAIL.addMessage(Translation.Controller_ParentDominionLost));
return;
}
if (!isContained(newCords, parent_dominion)) {
operator.setResponse(FAIL.addMessage("超出父领地 %s 范围", parent_dominion.getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_OutOfParentDominionRange, parent_dominion.getName()));
return;
}
// 获取同世界下的所有同级领地
@ -274,11 +280,11 @@ public class DominionController {
if (isIntersect(exist_dominion, newCords)) {
// 如果是自己跳过
if (exist_dominion.getId().equals(dominion.getId())) continue;
operator.setResponse(FAIL.addMessage("与领地 %s 冲突", exist_dominion.getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_ConflictWithDominion, exist_dominion.getName()));
return;
}
}
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功扩展领地 %s %d格", dominion_name, size);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_ExpandDominionSuccess, dominion_name, size);
// 检查经济
if (handleEconomyFailed(operator, Dominion.config.getEconomyOnlyXZ(operator.getPlayer()) ? sqr(newCords) - dominion.getSquare() : vol(newCords) - dominion.getVolume()
, true, FAIL, SUCCESS)) return;
@ -299,7 +305,7 @@ public class DominionController {
public static void contract(AbstractOperator operator, Integer size) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你所处的领地,请指定名称"));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_CannotGetDominionAuto));
return;
}
contract(operator, size, dominion.getName());
@ -313,7 +319,7 @@ public class DominionController {
* @param dominion_name 领地名称
*/
public static void contract(AbstractOperator operator, Integer size, String dominion_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "缩小领地失败");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_ContractDominionFailed);
DominionDTO dominion = expandContractPreCheck(operator, getExistDomAndIsOwner(operator, dominion_name), FAIL);
if (dominion == null) {
return;
@ -326,11 +332,11 @@ public class DominionController {
List<DominionDTO> sub_dominions = DominionDTO.selectByParentId(dominion.getWorldUid(), dominion.getId());
for (DominionDTO sub_dominion : sub_dominions) {
if (!isContained(sub_dominion, newCords)) {
operator.setResponse(FAIL.addMessage("缩小后的领地无法包含子领地 %s", sub_dominion.getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_ContractDominionConflict, sub_dominion.getName()));
return;
}
}
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功缩小领地 %s %d格", dominion_name, size);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_ContractDominionSuccess, dominion_name, size);
// 退还经济
if (handleEconomyFailed(operator, Dominion.config.getEconomyOnlyXZ(operator.getPlayer()) ? dominion.getSquare() - sqr(newCords) : dominion.getVolume() - vol(newCords)
, false, FAIL, SUCCESS)) return;
@ -364,18 +370,18 @@ public class DominionController {
* @param force 是否强制删除
*/
public static void delete(AbstractOperator operator, String dominion_name, boolean force) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "删除领地失败");
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "领地 %s 及其所有子领地已删除", dominion_name);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_DeleteDominionFailed);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_DeleteDominionSuccess, dominion_name);
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
return;
}
List<DominionDTO> sub_dominions = getSubDominionsRecursive(dominion);
if (!force) {
AbstractOperator.Result WARNING = new AbstractOperator.Result(AbstractOperator.Result.WARNING, "删除领地 %s 会同时删除其所有子领地,是否继续?", dominion_name);
AbstractOperator.Result WARNING = new AbstractOperator.Result(AbstractOperator.Result.WARNING, Translation.Controller_DeleteDominionConfirm, dominion_name);
showSubNamesWarning(sub_dominions, WARNING);
if (operator instanceof BukkitPlayerOperator) {
Notification.warn(operator.getPlayer(), "输入 /dominion delete %s force 确认删除", dominion_name);
Notification.warn(operator.getPlayer(), Translation.Controller_DeleteDominionForceConfirm, dominion_name);
}
operator.setResponse(WARNING);
return;
@ -425,7 +431,7 @@ public class DominionController {
return;
}
dominion.setJoinMessage(message);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功设置领地 %s 的进入消息", dominion_name));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_SetEnterMessageSuccess, dominion_name));
}
/**
@ -455,7 +461,7 @@ public class DominionController {
return;
}
dominion.setLeaveMessage(message);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功设置领地 %s 的离开消息", dominion_name));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_SetLeaveMessageSuccess, dominion_name));
}
/**
@ -478,15 +484,15 @@ public class DominionController {
* @param dominion_name 领地名称
*/
public static void setTpLocation(AbstractOperator operator, int x, int y, int z, String dominion_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置领地传送点失败");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_SetTpLocationFailed);
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在", dominion_name));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_DominionNotExist, dominion_name));
return;
}
World world = dominion.getWorld();
if (world == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地所在世界不存在"));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_DominionWorldNotExist));
return;
}
Location loc = new Location(world, x, y, z);
@ -495,10 +501,10 @@ public class DominionController {
loc.setY(loc.getY() + 1.5);
dominion.setTpLocation(loc);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS,
"成功设置领地 %s 的传送点 %d %d %d", dominion_name
Translation.Controller_SetTpLocationSuccess, dominion_name
, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
} else {
operator.setResponse(FAIL.addMessage("传送点不在领地 %s 内", dominion_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_TpLocationNotInDominion, dominion_name));
}
}
@ -510,17 +516,17 @@ public class DominionController {
* @param new_name 新名称
*/
public static void rename(AbstractOperator operator, String old_name, String new_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "重命名领地失败");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_RenameDominionFailed);
if (new_name.isEmpty()) {
operator.setResponse(FAIL.addMessage("新名称不能为空"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNameShouldNotEmpty));
return;
}
if (new_name.contains(" ") || new_name.contains(".")) {
operator.setResponse(FAIL.addMessage("领地名称不能包含空格或点"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNameInvalid));
return;
}
if (Objects.equals(old_name, new_name)) {
operator.setResponse(FAIL.addMessage("新名称与旧名称相同"));
operator.setResponse(FAIL.addMessage(Translation.Controller_RenameDominionSameName));
return;
}
DominionDTO dominion = getExistDomAndIsOwner(operator, old_name);
@ -528,11 +534,11 @@ public class DominionController {
return;
}
if (DominionDTO.select(new_name) != null) {
operator.setResponse(FAIL.addMessage("已经存在名称为 %s 的领地", new_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNameExist, new_name));
return;
}
dominion.setName(new_name);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功将领地 %s 重命名为 %s", old_name, new_name));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_RenameDominionSuccess, old_name, new_name));
}
/**
@ -544,35 +550,30 @@ public class DominionController {
* @param force 是否强制转让
*/
public static void give(AbstractOperator operator, String dom_name, String player_name, boolean force) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "转让领地失败");
PlayerDTO operatorDTO = PlayerDTO.select(operator.getUniqueId());
if (operatorDTO == null) {
operator.setResponse(FAIL.addMessage("操作者信息丢失,请联系管理员"));
return;
}
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_GiveDominionFailed);
DominionDTO dominion = getExistDomAndIsOwner(operator, dom_name);
if (dominion == null) {
return;
}
PlayerDTO player = PlayerController.getPlayerDTO(player_name);
if (player == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在", player_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerNotExist, player_name));
return;
}
if (Objects.equals(dominion.getOwner(), player.getUuid())) {
operator.setResponse(FAIL.addMessage("领地 %s 已经属于 %s无需转移", dom_name, player_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionAlreadyBelong, dom_name, player_name));
return;
}
if (dominion.getParentDomId() != -1) {
operator.setResponse(FAIL.addMessage("子领地无法转让,你可以通过将 %s 设置为管理员来让其管理领地 %s ", player_name, dom_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_SubDominionCannotGive, player_name, dom_name));
return;
}
List<DominionDTO> sub_dominions = getSubDominionsRecursive(dominion);
if (!force) {
AbstractOperator.Result WARNING = new AbstractOperator.Result(AbstractOperator.Result.WARNING, "转让领地 %s 给 %s 会同时转让其所有子领地,是否继续?", dom_name, player_name);
AbstractOperator.Result WARNING = new AbstractOperator.Result(AbstractOperator.Result.WARNING, Translation.Controller_GiveDominionConfirm, dom_name, player_name);
showSubNamesWarning(sub_dominions, WARNING);
if (operator instanceof BukkitPlayerOperator) {
Notification.warn(operator.getPlayer(), "输入 /dominion give %s %s force 确认转让", dom_name, player_name);
Notification.warn(operator.getPlayer(), Translation.Controller_GiveDominionForceConfirm, dom_name, player_name);
}
operator.setResponse(WARNING);
return;
@ -581,7 +582,7 @@ public class DominionController {
for (DominionDTO sub_dominion : sub_dominions) {
sub_dominion.setOwner(player.getUuid());
}
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功将领地 %s 及其所有子领地转让给 %s", dom_name, player_name));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_GiveDominionSuccess, dom_name, player_name));
}
/**
@ -592,22 +593,18 @@ public class DominionController {
* @param dom_name 领地名称
*/
public static void setMapColor(AbstractOperator operator, String color, String dom_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置领地地图颜色失败");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_SetMapColorFailed);
DominionDTO dominion = getExistDomAndIsOwner(operator, dom_name);
if (dominion == null) {
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者", dom_name));
return;
}
color = color.toUpperCase(); // 转换为大写
if (!color.matches("^#[0-9a-fA-F]{6}$")) {
operator.setResponse(FAIL.addMessage("颜色格式不正确"));
operator.setResponse(FAIL.addMessage(Translation.Controller_MapColorInvalid));
return;
}
dominion.setColor(color);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功设置领地 %s 的卫星地图颜色为 %s", dom_name, color));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_SetMapColorSuccess, dom_name, color));
}
/**
@ -617,10 +614,10 @@ public class DominionController {
* @param color 16进制颜色 例如 #ff0000
*/
public static void setMapColor(AbstractOperator operator, String color) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置领地地图颜色失败");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_SetMapColorFailed);
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("无法获取你所处的领地,请指定名称"));
operator.setResponse(FAIL.addMessage(Translation.Controller_CannotGetDominionAuto));
return;
}
setMapColor(operator, color, dominion.getName());
@ -699,7 +696,7 @@ public class DominionController {
}
private static boolean sizeNotValid(AbstractOperator operator, int x1, int y1, int z1, int x2, int y2, int z2) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "尺寸不合法");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_SizeInvalid);
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
return false;
}
@ -723,34 +720,34 @@ public class DominionController {
int y_length = y2 - y1;
int z_length = z2 - z1;
if (x_length < 4 || y_length < 4 || z_length < 4) {
operator.setResponse(FAIL.addMessage("领地的任意一边长度不得小于4"));
operator.setResponse(FAIL.addMessage(Translation.Controller_SizeShouldBeGreaterThan4));
return true;
}
if (x_length > Dominion.config.getLimitSizeX(operator.getPlayer()) && Dominion.config.getLimitSizeX(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage("领地X方向长度不能超过 %d", Dominion.config.getLimitSizeX(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_SizeXShouldBeLessThan, Dominion.config.getLimitSizeX(operator.getPlayer())));
return true;
}
if (y_length > Dominion.config.getLimitSizeY(operator.getPlayer()) && Dominion.config.getLimitSizeY(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage("领地Y方向高度不能超过 %d", Dominion.config.getLimitSizeY(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_SizeYShouldBeLessThan, Dominion.config.getLimitSizeY(operator.getPlayer())));
return true;
}
if (z_length > Dominion.config.getLimitSizeZ(operator.getPlayer()) && Dominion.config.getLimitSizeZ(operator.getPlayer()) > 0) {
operator.setResponse(FAIL.addMessage("领地Z方向长度不能超过 %d", Dominion.config.getLimitSizeZ(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_SizeZShouldBeLessThan, Dominion.config.getLimitSizeZ(operator.getPlayer())));
return true;
}
if (y2 > Dominion.config.getLimitMaxY(operator.getPlayer())) {
operator.setResponse(FAIL.addMessage("领地Y坐标不能超过 %d", Dominion.config.getLimitMaxY(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_MaxYShouldBeLessThan, Dominion.config.getLimitMaxY(operator.getPlayer())));
return true;
}
if (y1 < Dominion.config.getLimitMinY(operator.getPlayer())) {
operator.setResponse(FAIL.addMessage("领地Y坐标不能低于 %d", Dominion.config.getLimitMinY(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_MinYShouldBeLessThan, Dominion.config.getLimitMinY(operator.getPlayer())));
return true;
}
return false;
}
private static boolean depthNotValid(AbstractOperator operator, DominionDTO parent_dom) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "子领地深度不合法");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_DepthInvalid);
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
return false;
}
@ -758,7 +755,7 @@ public class DominionController {
return false;
}
if (parent_dom.getId() != -1 && Dominion.config.getLimitDepth(operator.getPlayer()) == 0) {
operator.setResponse(FAIL.addMessage("不允许创建子领地"));
operator.setResponse(FAIL.addMessage(Translation.Controller_CreateSubDominionDisabled));
return true;
}
if (parent_dom.getId() == -1) {
@ -770,7 +767,7 @@ public class DominionController {
level++;
}
if (level >= Dominion.config.getLimitDepth(operator.getPlayer())) {
operator.setResponse(FAIL.addMessage("子领地嵌套深度不能超过 %d", Dominion.config.getLimitDepth(operator.getPlayer())));
operator.setResponse(FAIL.addMessage(Translation.Controller_DepthShouldBeLessThan, Dominion.config.getLimitDepth(operator.getPlayer())));
return true;
}
return false;
@ -794,11 +791,11 @@ public class DominionController {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "");
DominionDTO dominion = DominionDTO.select(dominion_name);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", dominion_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, dominion_name));
return null;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者", dominion_name));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwner, dominion_name));
return null;
}
return dominion;
@ -816,25 +813,25 @@ public class DominionController {
private static boolean handleEconomyFailed(AbstractOperator operator, Integer count, boolean paid, AbstractOperator.Result FAIL, AbstractOperator.Result SUCCESS) {
if (Dominion.config.getEconomyEnable()) {
if (!VaultConnect.instance.economyAvailable()) {
operator.setResponse(FAIL.addMessage("没有可用的经济插件系统,请联系服主。"));
operator.setResponse(FAIL.addMessage(Translation.Controller_NoEconomyPlugin));
return true;
}
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
SUCCESS.addMessage("你是OP已跳过经济检查。");
SUCCESS.addMessage(Translation.Controller_OpBypassEconomyCheck);
return false;
}
float priceOrRefund = count * Dominion.config.getEconomyPrice(operator.getPlayer());
if (paid) {
if (VaultConnect.instance.getBalance(operator.getPlayer()) < priceOrRefund) {
operator.setResponse(FAIL.addMessage("你的余额不足,需要 %.2f %s", priceOrRefund, VaultConnect.instance.currencyNamePlural()));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotEnoughMoney, priceOrRefund, VaultConnect.instance.currencyNamePlural()));
return true;
}
SUCCESS.addMessage("已扣除 %.2f %s", priceOrRefund, VaultConnect.instance.currencyNamePlural());
SUCCESS.addMessage(Translation.Controller_ChargeMoney, priceOrRefund, VaultConnect.instance.currencyNamePlural());
VaultConnect.instance.withdrawPlayer(operator.getPlayer(), priceOrRefund);
} else {
float refund = priceOrRefund * Dominion.config.getEconomyRefund(operator.getPlayer());
VaultConnect.instance.depositPlayer(operator.getPlayer(), refund);
SUCCESS.addMessage("已退还 %.2f %s", refund, VaultConnect.instance.currencyNamePlural());
SUCCESS.addMessage(Translation.Controller_RefundMoney, refund, VaultConnect.instance.currencyNamePlural());
}
}
return false;
@ -857,15 +854,15 @@ public class DominionController {
return null;
}
if (operator.getLocation() == null) {
operator.setResponse(FAIL.addMessage("无法获取你的位置"));
operator.setResponse(FAIL.addMessage(Translation.Controller_CannotGetLocation));
return null;
}
if (!operator.getLocation().getWorld().getUID().equals(dominion.getWorldUid())) {
operator.setResponse(FAIL.addMessage("禁止跨世界操作"));
operator.setResponse(FAIL.addMessage(Translation.Controller_CrossWorldOperationDisallowed));
return null;
}
if (!isInDominion(dominion, operator.getLocation())) {
operator.setResponse(FAIL.addMessage("你不在领地 %s 内,无法执行此操作", dominion.getName()));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotInDominion, dominion.getName()));
return null;
}
return dominion;
@ -874,7 +871,7 @@ public class DominionController {
private static int[] expandContractSizeChange(AbstractOperator operator, @NotNull DominionDTO dominion, boolean expand, int size, AbstractOperator.Result FAIL) {
BlockFace face = operator.getDirection();
if (face == null) {
operator.setResponse(FAIL.addMessage("无法获取你的方向"));
operator.setResponse(FAIL.addMessage(Translation.Controller_CannotGetDirection));
return null;
}
int[] result = new int[6];
@ -907,13 +904,13 @@ public class DominionController {
result[1] -= size;
break;
default:
operator.setResponse(FAIL.addMessage("无效的方向"));
operator.setResponse(FAIL.addMessage(Translation.Controller_InvalidDirection, face));
return null;
}
if (!expand) {
// 校验第二组坐标是否小于第一组坐标
if (result[0] > result[3] || result[1] > result[4] || result[2] > result[5]) {
operator.setResponse(FAIL.addMessage("缩小后的领地大小无效"));
operator.setResponse(FAIL.addMessage(Translation.Controller_ContractSizeInvalid));
return null;
}
}
@ -937,7 +934,7 @@ public class DominionController {
}
if (!sub_dominions.isEmpty()) {
sub_names = sub_names.substring(0, sub_names.length() - 2);
WARNING.addMessage("(子领地:%s)", sub_names);
WARNING.addMessage(Translation.Controller_SubDominionList, sub_names);
}
}

View File

@ -213,6 +213,149 @@ public class Translation extends Localization {
@i18nField(defaultValue = "使用称号失败:%s")
public static i18n Commands_UseTitleFailed;
@i18nField(defaultValue = "创建领地失败")
public static i18n Controller_CreateDominionFailed;
@i18nField(defaultValue = "成功创建领地 %s")
public static i18n Controller_CreateDominionSuccess;
@i18nField(defaultValue = "领地名称不能为空")
public static i18n Controller_DominionNameShouldNotEmpty;
@i18nField(defaultValue = "领地名称不能包含空格或点")
public static i18n Controller_DominionNameInvalid;
@i18nField(defaultValue = "已经存在名称为 %s 的领地")
public static i18n Controller_DominionNameExist;
@i18nField(defaultValue = "两个选点世界不一致")
public static i18n Controller_SelectPointsWorldNotSame;
@i18nField(defaultValue = "禁止在世界 %s 创建领地")
public static i18n Controller_CreateDominionDisabledWorld;
@i18nField(defaultValue = "你的领地数量已达上限(%d个)")
public static i18n Controller_DominionAmountLimit;
@i18nField(defaultValue = "父领地 %s 不存在")
public static i18n Controller_ParentDominionNotExist;
@i18nField(defaultValue = "根领地丢失!")
public static i18n Controller_RootDominionLost;
@i18nField(defaultValue = "你不是父领地 %s 的拥有者,无法创建子领地")
public static i18n Controller_NotParentDominionOwner;
@i18nField(defaultValue = "父领地与子领地不在同一世界")
public static i18n Controller_ParentDominionNotInSameWorld;
@i18nField(defaultValue = "超出父领地 %s 范围")
public static i18n Controller_OutOfParentDominionRange;
@i18nField(defaultValue = "与出生点保护冲突")
public static i18n Controller_ConflictWithSpawnProtect;
@i18nField(defaultValue = "与领地 %s 冲突")
public static i18n Controller_ConflictWithDominion;
@i18nField(defaultValue = "创建领地失败,数据库错误,请联系管理员")
public static i18n Controller_CreateDominionDatabaseError;
@i18nField(defaultValue = "无法获取你所处的领地,请指定名称")
public static i18n Controller_CannotGetDominionAuto;
@i18nField(defaultValue = "扩展领地失败")
public static i18n Controller_ExpandDominionFailed;
@i18nField(defaultValue = "领地所在世界丢失")
public static i18n Controller_DominionWorldLost;
@i18nField(defaultValue = "父领地丢失")
public static i18n Controller_ParentDominionLost;
@i18nField(defaultValue = "成功扩展领地 %s %d格")
public static i18n Controller_ExpandDominionSuccess;
@i18nField(defaultValue = "缩小领地失败")
public static i18n Controller_ContractDominionFailed;
@i18nField(defaultValue = "缩小后的领地无法包含子领地 %s")
public static i18n Controller_ContractDominionConflict;
@i18nField(defaultValue = "成功缩小领地 %s %d格")
public static i18n Controller_ContractDominionSuccess;
@i18nField(defaultValue = "删除领地失败")
public static i18n Controller_DeleteDominionFailed;
@i18nField(defaultValue = "领地 %s 及其所有子领地已删除")
public static i18n Controller_DeleteDominionSuccess;
@i18nField(defaultValue = "删除领地 %s 会同时删除其所有子领地,是否继续?")
public static i18n Controller_DeleteDominionConfirm;
@i18nField(defaultValue = "输入 /dominion delete %s force 确认删除")
public static i18n Controller_DeleteDominionForceConfirm;
@i18nField(defaultValue = "成功设置领地 %s 的进入消息")
public static i18n Controller_SetEnterMessageSuccess;
@i18nField(defaultValue = "成功设置领地 %s 的离开消息")
public static i18n Controller_SetLeaveMessageSuccess;
@i18nField(defaultValue = "设置领地传送点失败")
public static i18n Controller_SetTpLocationFailed;
@i18nField(defaultValue = "领地 %s 不存在")
public static i18n Controller_DominionNotExist;
@i18nField(defaultValue = "领地所在世界不存在")
public static i18n Controller_DominionWorldNotExist;
@i18nField(defaultValue = "成功设置领地 %s 的传送点 %d %d %d")
public static i18n Controller_SetTpLocationSuccess;
@i18nField(defaultValue = "传送点不在领地 %s 内")
public static i18n Controller_TpLocationNotInDominion;
@i18nField(defaultValue = "重命名领地失败")
public static i18n Controller_RenameDominionFailed;
@i18nField(defaultValue = "新名称与旧名称相同")
public static i18n Controller_RenameDominionSameName;
@i18nField(defaultValue = "成功将领地 %s 重命名为 %s")
public static i18n Controller_RenameDominionSuccess;
@i18nField(defaultValue = "转让领地失败")
public static i18n Controller_GiveDominionFailed;
@i18nField(defaultValue = "玩家 %s 不存在")
public static i18n Controller_PlayerNotExist;
@i18nField(defaultValue = "领地 %s 已经属于 %s无需转移")
public static i18n Controller_DominionAlreadyBelong;
@i18nField(defaultValue = "子领地无法转让,你可以通过将 %s 设置为管理员来让其管理领地 %s")
public static i18n Controller_SubDominionCannotGive;
@i18nField(defaultValue = "转让领地 %s 给 %s 会同时转让其所有子领地,是否继续?")
public static i18n Controller_GiveDominionConfirm;
@i18nField(defaultValue = "输入 /dominion give %s %s force 确认转让")
public static i18n Controller_GiveDominionForceConfirm;
@i18nField(defaultValue = "成功将领地 %s 及其所有子领地转让给 %s")
public static i18n Controller_GiveDominionSuccess;
@i18nField(defaultValue = "设置领地地图颜色失败")
public static i18n Controller_SetMapColorFailed;
@i18nField(defaultValue = "颜色格式不正确")
public static i18n Controller_MapColorInvalid;
@i18nField(defaultValue = "成功设置领地 %s 的卫星地图颜色为 %s")
public static i18n Controller_SetMapColorSuccess;
@i18nField(defaultValue = "尺寸不合法")
public static i18n Controller_SizeInvalid;
@i18nField(defaultValue = "领地的任意一边长度不得小于4")
public static i18n Controller_SizeShouldBeGreaterThan4;
@i18nField(defaultValue = "领地X方向(东西)长度不能超过 %d")
public static i18n Controller_SizeXShouldBeLessThan;
@i18nField(defaultValue = "领地Y方向(上下)高度不能超过 %d")
public static i18n Controller_SizeYShouldBeLessThan;
@i18nField(defaultValue = "领地Z方向(南北)长度不能超过 %d")
public static i18n Controller_SizeZShouldBeLessThan;
@i18nField(defaultValue = "领地Y坐标上限不能超过 %d")
public static i18n Controller_MaxYShouldBeLessThan;
@i18nField(defaultValue = "领地Y坐标下限不能超过 %d")
public static i18n Controller_MinYShouldBeLessThan;
@i18nField(defaultValue = "子领地深度不合法")
public static i18n Controller_DepthInvalid;
@i18nField(defaultValue = "不允许创建子领地")
public static i18n Controller_CreateSubDominionDisabled;
@i18nField(defaultValue = "子领地嵌套深度不能超过 %d")
public static i18n Controller_DepthShouldBeLessThan;
@i18nField(defaultValue = "你不是领地 %s 的拥有者")
public static i18n Controller_NotDominionOwner;
@i18nField(defaultValue = "没有可用的经济插件系统,请联系服主")
public static i18n Controller_NoEconomyPlugin;
@i18nField(defaultValue = "你是OP已跳过经济检查")
public static i18n Controller_OpBypassEconomyCheck;
@i18nField(defaultValue = "你的余额不足,需要 %.2f %s")
public static i18n Controller_NotEnoughMoney;
@i18nField(defaultValue = "已扣除 %.2f %s")
public static i18n Controller_ChargeMoney;
@i18nField(defaultValue = "已退还 %.2f %s")
public static i18n Controller_RefundMoney;
@i18nField(defaultValue = "无法获取你的位置")
public static i18n Controller_CannotGetLocation;
@i18nField(defaultValue = "禁止跨世界操作")
public static i18n Controller_CrossWorldOperationDisallowed;
@i18nField(defaultValue = "你不在领地 %s 内,无法执行此操作")
public static i18n Controller_NotInDominion;
@i18nField(defaultValue = "无法获取你的方向")
public static i18n Controller_CannotGetDirection;
@i18nField(defaultValue = "无效的方向 %s")
public static i18n Controller_InvalidDirection;
@i18nField(defaultValue = "缩小后的领地大小无效")
public static i18n Controller_ContractSizeInvalid;
@i18nField(defaultValue = "(子领地:%s)")
public static i18n Controller_SubDominionList;
@i18nField(defaultValue = "AutoCreateRadius 不能等于 0已重置为 10")
public static i18n Config_AutoCreateRadiusError;
@i18nField(defaultValue = "AutoCleanAfterDays 不能等于 0已重置为 180")