mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2025-01-27 10:34:16 +08:00
初步实现mysql支持,初步测试了三种数据库(暂无问题)
This commit is contained in:
parent
cac0b91734
commit
6f0b97f458
@ -30,13 +30,13 @@
|
||||
|
||||
## 功能介绍
|
||||
|
||||
- 支持 Postgresql 或 sqlite 存储数据;
|
||||
- 支持 Postgresql、Mysql、Sqlite3 存储数据;
|
||||
- 支持BlueMap卫星地图渲染;
|
||||
- 支持为玩家单独设置特权;
|
||||
- 支持设置领地管理员;
|
||||
- 支持子领地;
|
||||
- 采用 TUI 方式进行权限配置交互,简单快捷;
|
||||
- 支持基础价格系统;
|
||||
- 支持经济系统(需要 Vault 前置);
|
||||
- 领地区域可视化;
|
||||
- 管理员可在游戏内使用TUI配置领地系统;
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>Dominion</artifactId>
|
||||
<version>1.33.1-beta</version>
|
||||
<version>1.33.1-mysql-beta</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Dominion</name>
|
||||
|
@ -103,12 +103,17 @@ public class PrivilegeController {
|
||||
privilege = createPlayerPrivilege(operator, player.getUuid(), dominion);
|
||||
if (privilege == null) return;
|
||||
}
|
||||
if (flag.equals("admin") || privilege.getAdmin()) {
|
||||
if (privilege.getAdmin()) {
|
||||
if (notOwner(operator, dominion)) {
|
||||
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法修改其他管理员的权限", dominionName));
|
||||
return;
|
||||
}
|
||||
privilege.setAdmin(value);
|
||||
if (flag.equals("admin")) {
|
||||
privilege.setAdmin(value);
|
||||
} else {
|
||||
operator.setResponse(FAIL.addMessage("管理员拥有所有权限,无需单独设置权限"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Flag f = Flag.getFlag(flag);
|
||||
if (f == null) {
|
||||
|
@ -153,46 +153,6 @@ public class DominionDTO {
|
||||
query(sql, dominion.getId());
|
||||
}
|
||||
|
||||
private static DominionDTO update(DominionDTO dominion) {
|
||||
String tp_location;
|
||||
if (dominion.getTpLocation() == null) {
|
||||
tp_location = "default";
|
||||
} else {
|
||||
Location loc = dominion.getTpLocation();
|
||||
tp_location = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
}
|
||||
Field owner = new Field("owner", dominion.getOwner().toString());
|
||||
Field name = new Field("name", dominion.getName());
|
||||
Field world = new Field("world", dominion.getWorld());
|
||||
Field x1 = new Field("x1", dominion.getX1());
|
||||
Field y1 = new Field("y1", dominion.getY1());
|
||||
Field z1 = new Field("z1", dominion.getZ1());
|
||||
Field x2 = new Field("x2", dominion.getX2());
|
||||
Field y2 = new Field("y2", dominion.getY2());
|
||||
Field z2 = new Field("z2", dominion.getZ2());
|
||||
Field parentDomId = new Field("parent_dom_id", dominion.getParentDomId());
|
||||
Field joinMessage = new Field("join_message", dominion.getJoinMessage());
|
||||
Field leaveMessage = new Field("leave_message", dominion.getLeaveMessage());
|
||||
Field tpLocation = new Field("tp_location", tp_location);
|
||||
Field color = new Field("color", dominion.getColor());
|
||||
Field id = new Field("id", dominion.getId());
|
||||
UpdateRow update = new UpdateRow().returningAll(id).table("dominion").where("id = ?", id.value);
|
||||
for (Flag f : Flag.getDominionFlagsEnabled()) {
|
||||
update.field(new Field(f.getFlagName(), dominion.getFlagValue(f)));
|
||||
}
|
||||
update.field(owner).field(name).field(world).field(x1).field(y1).field(z1).field(x2).field(y2).field(z2)
|
||||
.field(parentDomId).field(joinMessage).field(leaveMessage).field(tpLocation).field(color);
|
||||
try {
|
||||
List<DominionDTO> dominions = getDTOFromRS(update.execute());
|
||||
Cache.instance.loadDominions();
|
||||
if (dominions.size() == 0) return null;
|
||||
return dominions.get(0);
|
||||
} catch (SQLException e) {
|
||||
DatabaseManager.handleDatabaseError("数据库操作失败: ", e, update.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private DominionDTO(Integer id, UUID owner, String name, String world,
|
||||
Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2,
|
||||
Integer parentDomId,
|
||||
@ -262,18 +222,30 @@ public class DominionDTO {
|
||||
return id;
|
||||
}
|
||||
|
||||
public DominionDTO setId(Integer id) {
|
||||
this.id = id;
|
||||
return update(this);
|
||||
}
|
||||
|
||||
public UUID getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
private DominionDTO doUpdate(UpdateRow updateRow) {
|
||||
Field id = new Field("id", this.id);
|
||||
updateRow.returningAll(id)
|
||||
.table("dominion")
|
||||
.where("id = ?", id.value);
|
||||
try (ResultSet rs = updateRow.execute()) {
|
||||
List<DominionDTO> dominions = getDTOFromRS(rs);
|
||||
if (dominions.size() == 0) return null;
|
||||
Cache.instance.loadDominions();
|
||||
return dominions.get(0);
|
||||
} catch (SQLException e) {
|
||||
DatabaseManager.handleDatabaseError("更新领地信息失败: ", e, updateRow.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public DominionDTO setOwner(UUID owner) {
|
||||
this.owner = owner;
|
||||
return update(this);
|
||||
Field ownerField = new Field("owner", owner.toString());
|
||||
return doUpdate(new UpdateRow().field(ownerField));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -282,7 +254,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setName(String name) {
|
||||
this.name = name;
|
||||
return update(this);
|
||||
Field nameField = new Field("name", name);
|
||||
return doUpdate(new UpdateRow().field(nameField));
|
||||
}
|
||||
|
||||
public String getWorld() {
|
||||
@ -295,7 +268,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setX1(Integer x1) {
|
||||
this.x1 = x1;
|
||||
return update(this);
|
||||
Field x1Field = new Field("x1", x1);
|
||||
return doUpdate(new UpdateRow().field(x1Field));
|
||||
}
|
||||
|
||||
public Integer getY1() {
|
||||
@ -304,7 +278,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setY1(Integer y1) {
|
||||
this.y1 = y1;
|
||||
return update(this);
|
||||
Field y1Field = new Field("y1", y1);
|
||||
return doUpdate(new UpdateRow().field(y1Field));
|
||||
}
|
||||
|
||||
public Integer getZ1() {
|
||||
@ -313,7 +288,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setZ1(Integer z1) {
|
||||
this.z1 = z1;
|
||||
return update(this);
|
||||
Field z1Field = new Field("z1", z1);
|
||||
return doUpdate(new UpdateRow().field(z1Field));
|
||||
}
|
||||
|
||||
public Integer getX2() {
|
||||
@ -322,7 +298,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setX2(Integer x2) {
|
||||
this.x2 = x2;
|
||||
return update(this);
|
||||
Field x2Field = new Field("x2", x2);
|
||||
return doUpdate(new UpdateRow().field(x2Field));
|
||||
}
|
||||
|
||||
public Integer getY2() {
|
||||
@ -331,7 +308,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setY2(Integer y2) {
|
||||
this.y2 = y2;
|
||||
return update(this);
|
||||
Field y2Field = new Field("y2", y2);
|
||||
return doUpdate(new UpdateRow().field(y2Field));
|
||||
}
|
||||
|
||||
public Integer getZ2() {
|
||||
@ -340,7 +318,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setZ2(Integer z2) {
|
||||
this.z2 = z2;
|
||||
return update(this);
|
||||
Field z2Field = new Field("z2", z2);
|
||||
return doUpdate(new UpdateRow().field(z2Field));
|
||||
}
|
||||
|
||||
public Integer getSquare() {
|
||||
@ -369,7 +348,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setParentDomId(Integer parentDomId) {
|
||||
this.parentDomId = parentDomId;
|
||||
return update(this);
|
||||
Field parentDomIdField = new Field("parent_dom_id", parentDomId);
|
||||
return doUpdate(new UpdateRow().field(parentDomIdField));
|
||||
}
|
||||
|
||||
public String getJoinMessage() {
|
||||
@ -378,7 +358,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setJoinMessage(String joinMessage) {
|
||||
this.joinMessage = joinMessage;
|
||||
return update(this);
|
||||
Field joinMessageField = new Field("join_message", joinMessage);
|
||||
return doUpdate(new UpdateRow().field(joinMessageField));
|
||||
}
|
||||
|
||||
public String getLeaveMessage() {
|
||||
@ -387,7 +368,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setLeaveMessage(String leaveMessage) {
|
||||
this.leaveMessage = leaveMessage;
|
||||
return update(this);
|
||||
Field leaveMessageField = new Field("leave_message", leaveMessage);
|
||||
return doUpdate(new UpdateRow().field(leaveMessageField));
|
||||
}
|
||||
|
||||
public Boolean getFlagValue(Flag flag) {
|
||||
@ -397,7 +379,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setFlagValue(Flag flag, Boolean value) {
|
||||
flags.put(flag, value);
|
||||
return update(this);
|
||||
Field flagField = new Field(flag.getFlagName(), value);
|
||||
return doUpdate(new UpdateRow().field(flagField));
|
||||
}
|
||||
|
||||
public DominionDTO setXYZ(Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2) {
|
||||
@ -407,7 +390,13 @@ public class DominionDTO {
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
this.z2 = z2;
|
||||
return update(this);
|
||||
Field x1Field = new Field("x1", x1);
|
||||
Field y1Field = new Field("y1", y1);
|
||||
Field z1Field = new Field("z1", z1);
|
||||
Field x2Field = new Field("x2", x2);
|
||||
Field y2Field = new Field("y2", y2);
|
||||
Field z2Field = new Field("z2", z2);
|
||||
return doUpdate(new UpdateRow().field(x1Field).field(y1Field).field(z1Field).field(x2Field).field(y2Field).field(z2Field));
|
||||
}
|
||||
|
||||
public Location getTpLocation() {
|
||||
@ -429,7 +418,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setTpLocation(Location loc) {
|
||||
this.tp_location = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
return update(this);
|
||||
Field tpLocationField = new Field("tp_location", tp_location);
|
||||
return doUpdate(new UpdateRow().field(tpLocationField));
|
||||
}
|
||||
|
||||
public Location getLocation1() {
|
||||
@ -442,7 +432,8 @@ public class DominionDTO {
|
||||
|
||||
public DominionDTO setColor(String color) {
|
||||
this.color = color;
|
||||
return update(this);
|
||||
Field colorField = new Field("color", color);
|
||||
return doUpdate(new UpdateRow().field(colorField));
|
||||
}
|
||||
|
||||
public int getColorR() {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lunadeer.dominion.dtos;
|
||||
|
||||
import cn.lunadeer.dominion.Cache;
|
||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
|
||||
@ -35,22 +36,15 @@ public class PlayerPrivilegeDTO {
|
||||
return players;
|
||||
}
|
||||
|
||||
private static PlayerPrivilegeDTO update(PlayerPrivilegeDTO player) {
|
||||
Field admin = new Field("admin", player.getAdmin());
|
||||
Field domID = new Field("dom_id", player.getDomID());
|
||||
Field id = new Field("id", player.getId());
|
||||
UpdateRow updateRow = new UpdateRow().returningAll(id)
|
||||
private PlayerPrivilegeDTO doUpdate(UpdateRow updateRow) {
|
||||
Field id = new Field("id", this.id);
|
||||
updateRow.returningAll(id)
|
||||
.table("player_privilege")
|
||||
.field(admin)
|
||||
.field(domID)
|
||||
.where("id = ?", id.value);
|
||||
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
|
||||
updateRow.field(new Field(f.getFlagName(), player.getFlagValue(f)));
|
||||
}
|
||||
try (ResultSet rs = updateRow.execute()) {
|
||||
Cache.instance.loadPlayerPrivileges();
|
||||
List<PlayerPrivilegeDTO> players = getDTOFromRS(rs);
|
||||
if (players.size() == 0) return null;
|
||||
Cache.instance.loadPlayerPrivileges();
|
||||
return players.get(0);
|
||||
} catch (Exception e) {
|
||||
DatabaseManager.handleDatabaseError("更新玩家权限失败: ", e, "");
|
||||
@ -138,20 +132,27 @@ public class PlayerPrivilegeDTO {
|
||||
|
||||
public PlayerPrivilegeDTO setFlagValue(Flag flag, Boolean value) {
|
||||
flags.put(flag, value);
|
||||
return update(this);
|
||||
Field f = new Field(flag.getFlagName(), value);
|
||||
UpdateRow updateRow = new UpdateRow().field(f);
|
||||
XLogger.debug("setFlagValue: " + updateRow.toString());
|
||||
return doUpdate(updateRow);
|
||||
}
|
||||
|
||||
public PlayerPrivilegeDTO setAdmin(Boolean admin) {
|
||||
this.admin = admin;
|
||||
return update(this);
|
||||
Field f = new Field("admin", admin);
|
||||
UpdateRow updateRow = new UpdateRow().field(f);
|
||||
return doUpdate(updateRow);
|
||||
}
|
||||
|
||||
public PlayerPrivilegeDTO applyTemplate(PrivilegeTemplateDTO template) {
|
||||
this.admin = template.getAdmin();
|
||||
UpdateRow updateRow = new UpdateRow().field(new Field("admin", admin));
|
||||
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
|
||||
this.flags.put(f, template.getFlagValue(f));
|
||||
updateRow.field(new Field(f.getFlagName(), template.getFlagValue(f)));
|
||||
}
|
||||
return update(this);
|
||||
return doUpdate(updateRow);
|
||||
}
|
||||
|
||||
private PlayerPrivilegeDTO(Integer id, UUID playerUUID, Boolean admin, Integer domID, Map<Flag, Boolean> flags) {
|
||||
|
@ -61,6 +61,21 @@ public class PrivilegeTemplateDTO {
|
||||
}
|
||||
}
|
||||
|
||||
private PrivilegeTemplateDTO doUpdate(UpdateRow updateRow) {
|
||||
Field id = new Field("id", this.id);
|
||||
updateRow.returningAll(id)
|
||||
.table("privilege_template")
|
||||
.where("id = ?", id.value);
|
||||
try (ResultSet rs = updateRow.execute()) {
|
||||
List<PrivilegeTemplateDTO> templates = getDTOFromRS(rs);
|
||||
if (templates.size() == 0) return null;
|
||||
return templates.get(0);
|
||||
} catch (Exception e) {
|
||||
DatabaseManager.handleDatabaseError("更新权限模版失败: ", 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);
|
||||
@ -116,34 +131,12 @@ public class PrivilegeTemplateDTO {
|
||||
|
||||
public PrivilegeTemplateDTO setFlagValue(Flag flag, Boolean value) {
|
||||
flags.put(flag, value);
|
||||
return update(this);
|
||||
return doUpdate(new UpdateRow().field(new Field(flag.getFlagName(), value)));
|
||||
}
|
||||
|
||||
public PrivilegeTemplateDTO setAdmin(Boolean admin) {
|
||||
this.admin = admin;
|
||||
return update(this);
|
||||
}
|
||||
|
||||
private static PrivilegeTemplateDTO update(PrivilegeTemplateDTO template) {
|
||||
Field name = new Field("name", template.getName());
|
||||
Field admin = new Field("admin", template.getAdmin());
|
||||
Field id = new Field("id", template.getId());
|
||||
UpdateRow updateRow = new UpdateRow().table("privilege_template")
|
||||
.field(name)
|
||||
.field(admin)
|
||||
.returningAll(id)
|
||||
.where("id = ?", id.value);
|
||||
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
|
||||
updateRow.field(new Field(f.getFlagName(), template.getFlagValue(f)));
|
||||
}
|
||||
try (ResultSet rs = updateRow.execute()) {
|
||||
List<PrivilegeTemplateDTO> templates = getDTOFromRS(rs);
|
||||
if (templates.size() == 0) return null;
|
||||
return templates.get(0);
|
||||
} catch (Exception e) {
|
||||
DatabaseManager.handleDatabaseError("更新权限模版失败: ", e, updateRow.toString());
|
||||
return null;
|
||||
}
|
||||
return doUpdate(new UpdateRow().field(new Field("admin", admin)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,9 +63,9 @@ public class PrivilegeInfo {
|
||||
view.add(Line.create()
|
||||
.append(Button.createRed("☐").setExecuteCommand("/dominion set_privilege " + playerName + " admin true " + dominion.getName() + " " + page).build())
|
||||
.append("管理员"));
|
||||
}
|
||||
for (Flag flag : Flag.getPrivilegeFlagsEnabled()) {
|
||||
view.add(createOption(flag, privilege.getFlagValue(flag), playerName, dominion.getName(), page));
|
||||
for (Flag flag : Flag.getPrivilegeFlagsEnabled()) {
|
||||
view.add(createOption(flag, privilege.getFlagValue(flag), playerName, dominion.getName(), page));
|
||||
}
|
||||
}
|
||||
view.showOn(player, page);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user