Merge branch 'master' into global-teleportation

# Conflicts:
#	pom.xml
#	src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java
#	src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
This commit is contained in:
zhangyuheng 2024-07-08 01:18:37 +08:00
commit 59ccbbdd5c
9 changed files with 35 additions and 37 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.35.0-global-tp-beta</version>
<version>1.35.8-global-tp-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>

View File

@ -27,7 +27,6 @@ public final class Dominion extends JavaPlugin {
new Notification(this);
new XLogger(this);
config = new ConfigManager(this);
XLogger.setDebug(config.isDebug());
new DatabaseManager(this,
DatabaseType.valueOf(config.getDbType().toUpperCase()),
config.getDbHost(),
@ -39,9 +38,6 @@ public final class Dominion extends JavaPlugin {
new Scheduler(this);
AutoClean.run();
Cache.instance = new Cache();
if (config.getEconomyEnable()) {
new VaultConnect(this);
}
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
Bukkit.getPluginManager().registerEvents(new EnvironmentEvents(), this);
@ -49,6 +45,8 @@ public final class Dominion extends JavaPlugin {
Objects.requireNonNull(Bukkit.getPluginCommand("dominion")).setExecutor(new Commands());
bStatsMetrics metrics = new bStatsMetrics(this, 21445);
metrics.addCustomChart(new bStatsMetrics.SimplePie("database", () -> config.getDbType()));
if (config.getCheckUpdate()) {
giteaReleaseCheck = new GiteaReleaseCheck(this,
"https://ssl.lunadeer.cn:14446",

View File

@ -36,7 +36,7 @@ public class Apis {
Notification.info(sender, " 领地的对角点坐标: x1=%d y1=%d z1=%d, x2=%d y2=%d z2=%d", x1, y1, z1, x2, y2, z2);
}
public static void autoPoints(Player player) {
public static Map<Integer, Location> autoPoints(Player player) {
Integer size = Dominion.config.getAutoCreateRadius();
Location location = player.getLocation();
Location location1 = new Location(location.getWorld(), location.getX() - size, location.getY() - size, location.getZ() - size);
@ -49,6 +49,7 @@ public class Apis {
points.put(0, location1);
points.put(1, location2);
Dominion.pointsSelect.put(player.getUniqueId(), points);
return points;
}
public static boolean notOpOrConsole(CommandSender sender) {

View File

@ -69,12 +69,12 @@ public class DominionController {
* @param name 领地名称
* @param loc1 位置1
* @param loc2 位置2
* @param parent_dominion_name 父领地名称
* @param parent_dominion_name 父领地名称(留空表示为根领地)
* @param skipEco 是否跳过经济检查
*/
public static void create(AbstractOperator operator, String name,
Location loc1, Location loc2,
String parent_dominion_name, boolean skipEco) {
@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);
if (name.isEmpty()) {
@ -109,12 +109,8 @@ public class DominionController {
loc2.getBlockX(), loc2.getBlockY(), loc2.getBlockZ())) {
return;
}
DominionDTO dominion = new DominionDTO(operator.getUniqueId(), name, loc1.getWorld().getName(),
(int) Math.min(loc1.getX(), loc2.getX()), (int) Math.min(loc1.getY(), loc2.getY()),
(int) Math.min(loc1.getZ(), loc2.getZ()), (int) Math.max(loc1.getX(), loc2.getX()),
(int) Math.max(loc1.getY(), loc2.getY()), (int) Math.max(loc1.getZ(), loc2.getZ()));
DominionDTO parent_dominion;
if (parent_dominion_name.isEmpty()) {
if (parent_dominion_name.isEmpty() || parent_dominion_name.equals("root")) {
parent_dominion = DominionDTO.select(-1);
} else {
parent_dominion = DominionDTO.select(parent_dominion_name);
@ -133,6 +129,11 @@ public class DominionController {
return;
}
}
// 创建 dominion (此步骤不会写入数据)
DominionDTO dominion = DominionDTO.create(operator.getUniqueId(), name, loc1.getWorld().getName(),
(int) Math.min(loc1.getX(), loc2.getX()), (int) Math.min(loc1.getY(), loc2.getY()),
(int) Math.min(loc1.getZ(), loc2.getZ()), (int) Math.max(loc1.getX(), loc2.getX()),
(int) Math.max(loc1.getY(), loc2.getY()), (int) Math.max(loc1.getZ(), loc2.getZ()), parent_dominion);
// 如果parent_dominion不为-1 检查是否在同一世界
if (parent_dominion.getId() != -1 && !parent_dominion.getWorld().equals(dominion.getWorld())) {
operator.setResponse(FAIL.addMessage("父领地与子领地不在同一世界。"));
@ -718,7 +719,7 @@ public class DominionController {
level++;
}
if (level >= Dominion.config.getLimitDepth()) {
operator.setResponse(FAIL.addMessage("子领地嵌套深度不能超过 %s", Dominion.config.getLimitDepth()));
operator.setResponse(FAIL.addMessage("子领地嵌套深度不能超过 %d", Dominion.config.getLimitDepth()));
return true;
}
return false;

View File

@ -1,11 +1,9 @@
package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.controllers.AbstractOperator;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
import org.bukkit.Location;
@ -30,13 +28,9 @@ public class CreateDominion {
@Override
public void handleData(String input) {
XLogger.debug("createDominionCB.run: %s", input);
autoPoints(sender);
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
Map<Integer, Location> points = Dominion.pointsSelect.get(sender.getUniqueId());
if (points == null || points.get(0) == null || points.get(1) == null) {
Notification.error(sender, "自动选点失败");
return;
}
Map<Integer, Location> points = autoPoints(sender);
operator.getResponse().thenAccept(result -> {
if (Objects.equals(result.getStatus(), AbstractOperator.Result.SUCCESS)) {
DominionManage.show(sender, new String[]{"list"});

View File

@ -233,6 +233,11 @@ public class DominionDTO {
this(null, owner, name, world, x1, y1, z1, x2, y2, z2, -1);
}
public static DominionDTO create(UUID owner, String name, String world,
Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2, DominionDTO parent) {
return new DominionDTO(null, owner, name, world, x1, y1, z1, x2, y2, z2, parent == null ? -1 : parent.getId());
}
private final Field id = new Field("id", FieldType.INT);
private final Field owner = new Field("owner", FieldType.STRING);
private final Field name = new Field("name", FieldType.STRING);
@ -371,11 +376,6 @@ public class DominionDTO {
return (Integer) parentDomId.value;
}
public DominionDTO setParentDomId(Integer parentDomId) {
this.parentDomId.value = parentDomId;
return doUpdate(new UpdateRow().field(this.parentDomId));
}
public String getJoinMessage() {
return (String) joinMessage.value;
}
@ -425,7 +425,7 @@ public class DominionDTO {
}
public Location getTpLocation() {
if (Objects.equals(tp_location, "default")) {
if (Objects.equals(tp_location.value, "default")) {
return null;
} else {
// 0:0:0

View File

@ -103,7 +103,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // bed
public void onBedUse(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Player bukkitPlayer = event.getPlayer();
@ -165,7 +165,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // button
public void onButton(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Player player = event.getPlayer();
@ -182,7 +182,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // cake
public void eatCake(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();
@ -280,7 +280,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // comparer
public void comparerChange(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();
@ -298,7 +298,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // door
public void doorUse(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();
@ -340,7 +340,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // edit sign
public void onSignOpen(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Player player = event.getPlayer();
@ -444,7 +444,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // honey
public void honeyInteractive(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();
@ -502,7 +502,7 @@ public class PlayerEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // lever
public void onLever(PlayerInteractEvent event) {
if (!event.getAction().isRightClick()) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();

View File

@ -2,6 +2,7 @@ package cn.lunadeer.dominion.managers;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.minecraftpluginutils.VaultConnect;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
@ -82,6 +83,9 @@ public class ConfigManager {
_economy_price = (float) _file.getDouble("Economy.Price", 10.0);
_economy_only_xz = _file.getBoolean("Economy.OnlyXZ", false);
_economy_refund = (float) _file.getDouble("Economy.Refund", 0.85);
if (getEconomyEnable()) {
new VaultConnect(this._plugin);
}
_fly_permission_nodes = _file.getStringList("FlyPermissionNodes");
_residence_migration = _file.getBoolean("ResidenceMigration", false);
saveAll(); // 回写文件 防止文件中的数据不完整

View File

@ -34,7 +34,7 @@ public class TemplateSetting {
return;
}
ListView view = ListView.create(10, "/dominion template manage " + template.getName());
ListView view = ListView.create(10, "/dominion template setting " + template.getName());
view.title("模板 " + args[1] + " 权限管理");
view.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())