新增dynmap支持

This commit is contained in:
zhangyuheng 2024-07-10 11:56:22 +08:00
parent fb1736e0f2
commit 23eb35c8b3
11 changed files with 159 additions and 20 deletions

12
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId> <groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId> <artifactId>Dominion</artifactId>
<version>1.35.9-beta</version> <version>1.35.9-dynmap-beta</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Dominion</name> <name>Dominion</name>
@ -70,6 +70,10 @@
<id>lunadeer-repo</id> <id>lunadeer-repo</id>
<url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url> <url>https://ssl.lunadeer.cn:14454/repository/maven-snapshots/</url>
</repository> </repository>
<repository>
<id>MikeRepo</id>
<url>https://repo.mikeprimm.com/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -95,5 +99,11 @@
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>2.0</version> <version>2.0</version>
</dependency> </dependency>
<dependency>
<groupId>us.dynmap</groupId>
<artifactId>dynmap-api</artifactId>
<version>3.4-beta-3</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,6 +1,8 @@
package cn.lunadeer.dominion; package cn.lunadeer.dominion;
import cn.lunadeer.dominion.dtos.*; import cn.lunadeer.dominion.dtos.*;
import cn.lunadeer.dominion.utils.BlueMapConnect;
import cn.lunadeer.dominion.utils.MapRender;
import cn.lunadeer.dominion.utils.ResMigration; import cn.lunadeer.dominion.utils.ResMigration;
import cn.lunadeer.minecraftpluginutils.Notification; import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.ParticleRender; import cn.lunadeer.minecraftpluginutils.ParticleRender;
@ -90,7 +92,7 @@ public class Cache {
count = 1; count = 1;
} }
} }
BlueMapConnect.render(); MapRender.render();
recheckPlayerState = true; recheckPlayerState = true;
_last_update_dominion.set(System.currentTimeMillis()); _last_update_dominion.set(System.currentTimeMillis());
XLogger.debug("loadDominionsExecution cost: %d ms for %d dominions" XLogger.debug("loadDominionsExecution cost: %d ms for %d dominions"

View File

@ -1,11 +1,13 @@
package cn.lunadeer.dominion; package cn.lunadeer.dominion;
import cn.lunadeer.dominion.dtos.PrivilegeTemplateDTO;
import cn.lunadeer.dominion.events.EnvironmentEvents; import cn.lunadeer.dominion.events.EnvironmentEvents;
import cn.lunadeer.dominion.events.PlayerEvents; import cn.lunadeer.dominion.events.PlayerEvents;
import cn.lunadeer.dominion.events.SelectPointEvents; import cn.lunadeer.dominion.events.SelectPointEvents;
import cn.lunadeer.dominion.managers.ConfigManager; import cn.lunadeer.dominion.managers.ConfigManager;
import cn.lunadeer.dominion.managers.DatabaseTables; import cn.lunadeer.dominion.managers.DatabaseTables;
import cn.lunadeer.dominion.utils.BlueMapConnect;
import cn.lunadeer.dominion.utils.DynmapConnect;
import cn.lunadeer.dominion.utils.MapRender;
import cn.lunadeer.minecraftpluginutils.*; import cn.lunadeer.minecraftpluginutils.*;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager; import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseType; import cn.lunadeer.minecraftpluginutils.databse.DatabaseType;
@ -13,6 +15,7 @@ import cn.lunadeer.minecraftpluginutils.scui.CuiManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapCommonAPIListener;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -72,7 +75,8 @@ public final class Dominion extends JavaPlugin {
XLogger.info(" |_____/ \\___/|_| |_| |_|_|_| |_|_|\\___/|_| |_|"); XLogger.info(" |_____/ \\___/|_| |_| |_|_|_| |_|_|\\___/|_| |_|");
XLogger.info(" "); XLogger.info(" ");
Scheduler.runTaskLaterAsync(BlueMapConnect::render, 40 * 20); if (config.getDynmap()) DynmapCommonAPIListener.register(new DynmapConnect()); // 注册 Dynmap API
Scheduler.runTaskLaterAsync(MapRender::render, 40 * 20);
} }
@Override @Override

View File

@ -1,9 +1,10 @@
package cn.lunadeer.dominion.commands; package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.BlueMapConnect; import cn.lunadeer.dominion.utils.BlueMapConnect;
import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.utils.MapRender;
import cn.lunadeer.minecraftpluginutils.Notification; import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler; import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.XLogger;
@ -104,7 +105,7 @@ public class Operator {
Notification.error(sender, e.getMessage()); Notification.error(sender, e.getMessage());
} }
} }
BlueMapConnect.renderMCA(mca_cords); MapRender.renderMCA(mca_cords);
Notification.info(sender, "MCA文件列表已导出到 %s", folder.getAbsolutePath()); Notification.info(sender, "MCA文件列表已导出到 %s", folder.getAbsolutePath());
}); });
} }

View File

@ -433,4 +433,8 @@ public class DominionDTO {
public String getColor() { public String getColor() {
return (String) color.value; return (String) color.value;
} }
public int getColorHex() {
return (getColorR() << 16) + (getColorG() << 8) + getColorB();
}
} }

View File

@ -48,7 +48,8 @@ public class ConfigManager {
XLogger.err("Limit.SizeZ 尺寸不能小于 4已重置为 128"); XLogger.err("Limit.SizeZ 尺寸不能小于 4已重置为 128");
setLimitSizeZ(128); setLimitSizeZ(128);
} }
_blue_map = _file.getBoolean("BlueMap", true); _blue_map = _file.getBoolean("BlueMap", false);
_dynmap = _file.getBoolean("Dynmap", false);
_auto_clean_after_days = _file.getInt("AutoCleanAfterDays", 180); _auto_clean_after_days = _file.getInt("AutoCleanAfterDays", 180);
if (_auto_clean_after_days == 0) { if (_auto_clean_after_days == 0) {
XLogger.err("AutoCleanAfterDays 不能等于 0已重置为 180"); XLogger.err("AutoCleanAfterDays 不能等于 0已重置为 180");
@ -98,6 +99,7 @@ public class ConfigManager {
_file.set("Limit.SizeY", _limit_size_y); _file.set("Limit.SizeY", _limit_size_y);
_file.set("Limit.SizeZ", _limit_size_z); _file.set("Limit.SizeZ", _limit_size_z);
_file.set("BlueMap", _blue_map); _file.set("BlueMap", _blue_map);
_file.set("Dynmap", _dynmap);
_file.set("AutoCleanAfterDays", _auto_clean_after_days); _file.set("AutoCleanAfterDays", _auto_clean_after_days);
_file.set("Limit.MinY", _limit_min_y); _file.set("Limit.MinY", _limit_min_y);
_file.set("Limit.MaxY", _limit_max_y); _file.set("Limit.MaxY", _limit_max_y);
@ -220,10 +222,8 @@ public class ConfigManager {
return _blue_map; return _blue_map;
} }
public void setBlueMap(Boolean blue_map) { public Boolean getDynmap() {
_blue_map = blue_map; return _dynmap;
_file.set("BlueMap", blue_map);
_plugin.saveConfig();
} }
public Integer getAutoCleanAfterDays() { public Integer getAutoCleanAfterDays() {
@ -423,6 +423,7 @@ public class ConfigManager {
private Boolean _limit_op_bypass; private Boolean _limit_op_bypass;
private Boolean _blue_map; private Boolean _blue_map;
private Boolean _dynmap;
private Integer _auto_clean_after_days; private Integer _auto_clean_after_days;
private Integer _limit_min_y; private Integer _limit_min_y;
private Integer _limit_max_y; private Integer _limit_max_y;

View File

@ -1,5 +1,7 @@
package cn.lunadeer.dominion; package cn.lunadeer.dominion.utils;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO; import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.minecraftpluginutils.Scheduler; import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.XLogger; import cn.lunadeer.minecraftpluginutils.XLogger;
@ -15,9 +17,6 @@ import java.util.*;
public class BlueMapConnect { public class BlueMapConnect {
public static void render() { public static void render() {
if (!Dominion.config.getBlueMap()) {
return;
}
Scheduler.runTaskAsync(() -> { Scheduler.runTaskAsync(() -> {
try { try {
BlueMapAPI.getInstance().ifPresent(api -> { BlueMapAPI.getInstance().ifPresent(api -> {
@ -76,9 +75,6 @@ public class BlueMapConnect {
} }
public static void renderMCA(Map<String, List<String>> mca_files) { public static void renderMCA(Map<String, List<String>> mca_files) {
if (!Dominion.config.getBlueMap()) {
return;
}
Scheduler.runTaskAsync(() -> { Scheduler.runTaskAsync(() -> {
try { try {
BlueMapAPI.getInstance().ifPresent(api -> { BlueMapAPI.getInstance().ifPresent(api -> {

View File

@ -0,0 +1,88 @@
package cn.lunadeer.dominion.utils;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.XLogger;
import com.flowpowered.math.vector.Vector2d;
import de.bluecolored.bluemap.api.math.Shape;
import org.dynmap.DynmapCommonAPI;
import org.dynmap.DynmapCommonAPIListener;
import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class DynmapConnect extends DynmapCommonAPIListener {
public static DynmapConnect instance;
private MarkerSet markerSet;
@Override
public void apiEnabled(DynmapCommonAPI dynmapCommonAPI) {
MarkerAPI markerAPI = dynmapCommonAPI.getMarkerAPI();
this.markerSet = markerAPI.getMarkerSet("dominion");
if (this.markerSet == null) {
this.markerSet = markerAPI.createMarkerSet("dominion", "Dominion领地", null, false);
}
}
public void setDominionMarker(DominionDTO dominion) {
String nameLabel = "<div>" + dominion.getName() + "</div>";
double[] xx = {dominion.getX1(), dominion.getX2()};
double[] zz = {dominion.getZ1(), dominion.getZ2()};
AreaMarker marker = this.markerSet.createAreaMarker(
dominion.getId().toString(),
nameLabel,
true,
dominion.getWorld(),
xx,
zz,
false
);
marker.setFillStyle(0.2, dominion.getColorHex());
marker.setLineStyle(1, 0.8, dominion.getColorHex());
XLogger.debug("Add dominion marker: " + dominion.getName());
}
public void setDominionMarkers(List<DominionDTO> dominions) {
Scheduler.runTaskAsync(() -> {
for (DominionDTO dominion : dominions) {
this.setDominionMarker(dominion);
}
});
}
public void setMCAMarkers(Map<String, List<String>> mca_files) {
Scheduler.runTaskAsync(() -> {
for (Map.Entry<String, List<String>> entry : mca_files.entrySet()) {
for (String file : entry.getValue()) {
String[] cords = file.split("\\.");
int world_x1 = Integer.parseInt(cords[1]) * 512;
int world_x2 = (Integer.parseInt(cords[1]) + 1) * 512;
int world_z1 = Integer.parseInt(cords[2]) * 512;
int world_z2 = (Integer.parseInt(cords[2]) + 1) * 512;
String nameLabel = "<div>" + file + "</div>";
double[] xx = {world_x1, world_x2};
double[] zz = {world_z1, world_z2};
AreaMarker marker = this.markerSet.createAreaMarker(
file,
nameLabel,
true,
entry.getKey(),
xx,
zz,
false
);
marker.setFillStyle(0.2, 0x00CC00);
marker.setLineStyle(1, 0.8, 0x00CC00);
}
}
});
}
}

View File

@ -0,0 +1,31 @@
package cn.lunadeer.dominion.utils;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import java.util.List;
import java.util.Map;
public class MapRender {
public static void render() {
if (Dominion.config.getBlueMap()) {
BlueMapConnect.render();
}
if (Dominion.config.getDynmap()) {
DynmapConnect.instance.setDominionMarkers(Cache.instance.getDominions());
}
}
public static void renderMCA(Map<String, List<String>> mca_files) {
if (Dominion.config.getBlueMap()) {
BlueMapConnect.renderMCA(mca_files);
}
if (Dominion.config.getDynmap()) {
DynmapConnect.instance.setMCAMarkers(mca_files);
}
}
}

View File

@ -52,7 +52,8 @@ FlyPermissionNodes:
# 是否允许玩家从 Residence 迁移领地数据 # 是否允许玩家从 Residence 迁移领地数据
ResidenceMigration: false ResidenceMigration: false
BlueMap: true BlueMap: false
Dynmap: false
CheckUpdate: true CheckUpdate: true

View File

@ -4,8 +4,9 @@ main: cn.lunadeer.dominion.Dominion
api-version: '1.20' api-version: '1.20'
load: STARTUP load: STARTUP
folia-supported: true folia-supported: true
loadbefore: softdepend:
- Vault - Vault
- dynmap
commands: commands:
Dominion: Dominion:
description: 领地插件命令 description: 领地插件命令