增强了DominionDTO的api能力,现支持修改信息

This commit is contained in:
ZhangYuheng 2024-10-12 11:01:49 +08:00
parent 7fff24dacf
commit 01b329a3e7
2 changed files with 112 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package cn.lunadeer.dominion.api.dtos;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -23,6 +24,22 @@ public interface DominionDTO {
*/
@NotNull UUID getOwner();
/**
* 设置领地所有者设置成功后返回领地对象设置失败返回null
*
* @param owner 领地所有者 UUID
* @return 领地对象
*/
@Nullable DominionDTO setOwner(UUID owner);
/**
* 设置领地所有者设置成功后返回领地对象设置失败返回null
*
* @param owner 领地所有者
* @return 领地对象
*/
@Nullable DominionDTO setOwner(Player owner);
/**
* 获取领地名称
*
@ -30,6 +47,14 @@ public interface DominionDTO {
*/
@NotNull String getName();
/**
* 设置领地名称设置成功后返回领地对象设置失败返回null
*
* @param name 领地名称
* @return 领地对象
*/
@Nullable DominionDTO setName(String name);
/**
* 获取领地所在世界如果世界不存在则返回null
*
@ -87,6 +112,27 @@ public interface DominionDTO {
*/
@NotNull Integer getZ2();
/**
* 设置领地角点坐标设置成功后返回领地对象设置失败返回null
*
* @param x1 小角点X坐标
* @param y1 小角点Y坐标
* @param z1 小角点Z坐标
* @param x2 大角点X坐标
* @param y2 大角点Y坐标
* @param z2 大角点Z坐标
* @return 领地对象
*/
@Nullable DominionDTO setXYZ(Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2);
/**
* 设置领地角点坐标设置成功后返回领地对象设置失败返回null
*
* @param cords 领地角点坐标数组长度为6依次为 x1, y1, z1, x2, y2, z2
* @return 领地对象
*/
@Nullable DominionDTO setXYZ(int[] cords);
/**
* 获取领地面积
*
@ -129,24 +175,59 @@ public interface DominionDTO {
*/
@NotNull Integer getParentDomId();
/**
* 获取领地欢迎提示语
*
* @return 领地欢迎提示语
*/
@NotNull String getJoinMessage();
/**
* 设置领地欢迎提示语设置成功后返回领地对象设置失败返回null
*
* @param joinMessage 领地欢迎提示语
* @return 领地对象
*/
@Nullable DominionDTO setJoinMessage(String joinMessage);
/**
* 获取领地离开提示语
*
* @return 领地离开提示语
*/
@NotNull String getLeaveMessage();
/**
* 获取领地环境配置
* 设置领地离开提示语设置成功后返回领地对象设置失败返回null
*
* @param leaveMessage 领地离开提示语
* @return 领地对象
*/
@Nullable DominionDTO setLeaveMessage(String leaveMessage);
/**
* 获取领地所有环境配置
*
* @return 领地环境权限配置
*/
@NotNull Map<Flag, Boolean> getEnvironmentFlagValue();
/**
* 获取领地访客权限配置
* 获取领地访客所有权限配置
*
* @return 领地访客权限配置
*/
@NotNull Map<Flag, Boolean> getGuestPrivilegeFlagValue();
/**
* 设置领地某个环境配置或访客权限的值设置成功后返回领地对象设置失败返回null
*
* @param flag 权限
* @param value 权限值
* @return 领地对象
*/
@Nullable DominionDTO setFlagValue(Flag flag, Boolean value);
/**
* 获取领地传送点坐标
*

View File

@ -11,6 +11,7 @@ import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -244,16 +245,24 @@ public class DominionDTO implements cn.lunadeer.dominion.api.dtos.DominionDTO {
}
}
@Override
public DominionDTO setOwner(UUID owner) {
this.owner.value = owner.toString();
return doUpdate(new UpdateRow().field(this.owner));
}
@Override
public DominionDTO setOwner(Player owner) {
this.owner.value = owner.getUniqueId().toString();
return doUpdate(new UpdateRow().field(this.owner));
}
@Override
public @NotNull String getName() {
return (String) name.value;
}
@Override
public DominionDTO setName(String name) {
this.name.value = name;
return doUpdate(new UpdateRow().field(this.name));
@ -364,6 +373,7 @@ public class DominionDTO implements cn.lunadeer.dominion.api.dtos.DominionDTO {
return (String) joinMessage.value;
}
@Override
public DominionDTO setJoinMessage(String joinMessage) {
this.joinMessage.value = joinMessage;
return doUpdate(new UpdateRow().field(this.joinMessage));
@ -374,6 +384,7 @@ public class DominionDTO implements cn.lunadeer.dominion.api.dtos.DominionDTO {
return (String) leaveMessage.value;
}
@Override
public DominionDTO setLeaveMessage(String leaveMessage) {
this.leaveMessage.value = leaveMessage;
return doUpdate(new UpdateRow().field(this.leaveMessage));
@ -398,12 +409,14 @@ public class DominionDTO implements cn.lunadeer.dominion.api.dtos.DominionDTO {
.collect(HashMap::new, (m, e) -> m.put(e.getKey(), e.getValue()), HashMap::putAll);
}
@Override
public DominionDTO setFlagValue(Flag flag, Boolean value) {
flags.put(flag, value);
Field flagField = new Field(flag.getFlagName(), value);
return doUpdate(new UpdateRow().field(flagField));
}
@Override
public DominionDTO setXYZ(Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2) {
this.x1.value = x1;
this.y1.value = y1;
@ -411,9 +424,25 @@ public class DominionDTO implements cn.lunadeer.dominion.api.dtos.DominionDTO {
this.x2.value = x2;
this.y2.value = y2;
this.z2.value = z2;
if (x1 > x2) {
int tmp = x1;
this.x1.value = x2;
this.x2.value = tmp;
}
if (y1 > y2) {
int tmp = y1;
this.y1.value = y2;
this.y2.value = tmp;
}
if (z1 > z2) {
int tmp = z1;
this.z1.value = z2;
this.z2.value = tmp;
}
return doUpdate(new UpdateRow().field(this.x1).field(this.y1).field(this.z1).field(this.x2).field(this.y2).field(this.z2));
}
@Override
public DominionDTO setXYZ(int[] cords) {
if (cords.length == 6) {
return setXYZ(cords[0], cords[1], cords[2], cords[3], cords[4], cords[5]);