This commit is contained in:
parent
dd9664f407
commit
d55b46f657
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>Dominion</artifactId>
|
<artifactId>Dominion</artifactId>
|
||||||
<version>1.12.2-beta</version>
|
<version>1.13.4-beta</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Dominion</name>
|
<name>Dominion</name>
|
||||||
|
@ -68,4 +68,58 @@ public class BlueMapConnect {
|
|||||||
XLogger.err(e.getMessage());
|
XLogger.err(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void renderMCA(Map<String, List<String>> mca_files) {
|
||||||
|
if (!Dominion.config.getBlueMap()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
BlueMapAPI.getInstance().ifPresent(api -> {
|
||||||
|
for (String world : mca_files.keySet()) {
|
||||||
|
api.getWorld(world).ifPresent(bmWorld -> {
|
||||||
|
MarkerSet markerSet = MarkerSet.builder()
|
||||||
|
.label("MCA")
|
||||||
|
.defaultHidden(true)
|
||||||
|
.build();
|
||||||
|
for (String file : mca_files.get(world)) {
|
||||||
|
// r.-1.-1.mca
|
||||||
|
int mca_x = Integer.parseInt(file.split("\\.")[1]);
|
||||||
|
int mca_z = Integer.parseInt(file.split("\\.")[2]);
|
||||||
|
int world_x1 = mca_x * 512;
|
||||||
|
int world_x2 = (mca_x + 1) * 512;
|
||||||
|
int world_z1 = mca_z * 512;
|
||||||
|
int world_z2 = (mca_z + 1) * 512;
|
||||||
|
Collection<Vector2d> vectors = new ArrayList<>();
|
||||||
|
vectors.add(new Vector2d(world_x1 + 0.001, world_z1 + 0.001));
|
||||||
|
vectors.add(new Vector2d(world_x2 - 0.001, world_z1 + 0.001));
|
||||||
|
vectors.add(new Vector2d(world_x2 - 0.001, world_z2 - 0.001));
|
||||||
|
vectors.add(new Vector2d(world_x1 + 0.001, world_z2 - 0.001));
|
||||||
|
Shape shape = new Shape(vectors);
|
||||||
|
double x = vectors.iterator().next().getX();
|
||||||
|
double z = vectors.iterator().next().getY();
|
||||||
|
double y = -64;
|
||||||
|
|
||||||
|
Color line = new Color(0, 204, 0, 0.8F);
|
||||||
|
Color fill = new Color(0, 204, 0, 0.2F);
|
||||||
|
ExtrudeMarker marker = ExtrudeMarker.builder()
|
||||||
|
.label(file)
|
||||||
|
.position(x, y, z)
|
||||||
|
.shape(shape, -64, 320)
|
||||||
|
.lineColor(line)
|
||||||
|
.fillColor(fill)
|
||||||
|
.build();
|
||||||
|
markerSet.getMarkers()
|
||||||
|
.put(file, marker);
|
||||||
|
}
|
||||||
|
for (BlueMapMap map : bmWorld.getMaps()) {
|
||||||
|
map.getMarkerSets().put(world + "-" + markerSet.getLabel(), markerSet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
|
XLogger.warn("无法连接 BlueMap 插件,如果你不打算使用卫星地图渲染建议前往配置文件关闭此功能以避免下方的报错。");
|
||||||
|
XLogger.err(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,10 @@ public class Cache {
|
|||||||
return id_dominions.get(id);
|
return id_dominions.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DominionDTO> getDominions() {
|
||||||
|
return new ArrayList<>(id_dominions.values());
|
||||||
|
}
|
||||||
|
|
||||||
public static Cache instance;
|
public static Cache instance;
|
||||||
private ConcurrentHashMap<Integer, DominionDTO> id_dominions;
|
private ConcurrentHashMap<Integer, DominionDTO> id_dominions;
|
||||||
private ConcurrentHashMap<String, List<Integer>> world_dominions; // 所有领地
|
private ConcurrentHashMap<String, List<Integer>> world_dominions; // 所有领地
|
||||||
|
@ -134,6 +134,9 @@ public class Commands implements TabExecutor {
|
|||||||
case "reload_cache":
|
case "reload_cache":
|
||||||
Operator.reloadCache(sender, args);
|
Operator.reloadCache(sender, args);
|
||||||
break;
|
break;
|
||||||
|
case "export_mca":
|
||||||
|
Operator.exportMca(sender, args);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -163,7 +166,8 @@ public class Commands implements TabExecutor {
|
|||||||
"set_leave_msg",
|
"set_leave_msg",
|
||||||
"rename",
|
"rename",
|
||||||
"give",
|
"give",
|
||||||
"reload_cache"
|
"reload_cache",
|
||||||
|
"export_mca"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
|
@ -5,7 +5,7 @@ import cn.lunadeer.dominion.events.PlayerEvents;
|
|||||||
import cn.lunadeer.dominion.events.SelectPointEvents;
|
import cn.lunadeer.dominion.events.SelectPointEvents;
|
||||||
import cn.lunadeer.dominion.utils.ConfigManager;
|
import cn.lunadeer.dominion.utils.ConfigManager;
|
||||||
import cn.lunadeer.dominion.utils.Database;
|
import cn.lunadeer.dominion.utils.Database;
|
||||||
import cn.lunadeer.dominion.utils.Time;
|
import cn.lunadeer.dominion.utils.Scheduler;
|
||||||
import cn.lunadeer.dominion.utils.XLogger;
|
import cn.lunadeer.dominion.utils.XLogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -16,6 +16,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class Dominion extends JavaPlugin {
|
public final class Dominion extends JavaPlugin {
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ public final class Dominion extends JavaPlugin {
|
|||||||
config = new ConfigManager(this);
|
config = new ConfigManager(this);
|
||||||
dbConnection = Database.createConnection();
|
dbConnection = Database.createConnection();
|
||||||
Database.migrate();
|
Database.migrate();
|
||||||
|
scheduler = new Scheduler(this);
|
||||||
Cache.instance = new Cache();
|
Cache.instance = new Cache();
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
|
Bukkit.getPluginManager().registerEvents(new PlayerEvents(), this);
|
||||||
@ -46,8 +48,13 @@ public final class Dominion extends JavaPlugin {
|
|||||||
XLogger.info(" |_____/ \\___/|_| |_| |_|_|_| |_|_|\\___/|_| |_|");
|
XLogger.info(" |_____/ \\___/|_| |_| |_|_|_| |_|_|\\___/|_| |_|");
|
||||||
XLogger.info(" ");
|
XLogger.info(" ");
|
||||||
|
|
||||||
Time.runLater(this, AutoClean::run, 20 * 30);
|
scheduler.async.runDelayed(this, scheduledTask -> {
|
||||||
Time.runLater(this, BlueMapConnect::render, 20 * 60);
|
AutoClean.run();
|
||||||
|
}, 30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
scheduler.async.runDelayed(this, scheduledTask -> {
|
||||||
|
BlueMapConnect.render();
|
||||||
|
}, 40, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,4 +66,5 @@ public final class Dominion extends JavaPlugin {
|
|||||||
public static ConfigManager config;
|
public static ConfigManager config;
|
||||||
public static Connection dbConnection;
|
public static Connection dbConnection;
|
||||||
public static Map<UUID, Map<Integer, Location>> pointsSelect = new HashMap<>();
|
public static Map<UUID, Map<Integer, Location>> pointsSelect = new HashMap<>();
|
||||||
|
public static Scheduler scheduler;
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,106 @@
|
|||||||
package cn.lunadeer.dominion.commands;
|
package cn.lunadeer.dominion.commands;
|
||||||
|
|
||||||
|
import cn.lunadeer.dominion.BlueMapConnect;
|
||||||
import cn.lunadeer.dominion.Cache;
|
import cn.lunadeer.dominion.Cache;
|
||||||
|
import cn.lunadeer.dominion.Dominion;
|
||||||
|
import cn.lunadeer.dominion.dtos.DominionDTO;
|
||||||
import cn.lunadeer.dominion.utils.Notification;
|
import cn.lunadeer.dominion.utils.Notification;
|
||||||
|
import cn.lunadeer.dominion.utils.XLogger;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.lunadeer.dominion.commands.Apis.notOpOrConsole;
|
import static cn.lunadeer.dominion.commands.Apis.notOpOrConsole;
|
||||||
|
|
||||||
public class Operator {
|
public class Operator {
|
||||||
|
|
||||||
public static void reloadCache(CommandSender sender, String[] args){
|
public static void reloadCache(CommandSender sender, String[] args) {
|
||||||
if (notOpOrConsole(sender)) return;
|
if (notOpOrConsole(sender)) return;
|
||||||
|
Dominion.scheduler.async.runNow(Dominion.instance, ScheduledTask -> {
|
||||||
Notification.info(sender, "正在从数据库重新加载领地缓存...");
|
Notification.info(sender, "正在从数据库重新加载领地缓存...");
|
||||||
Cache.instance.loadDominions();
|
Cache.instance.loadDominions();
|
||||||
|
Notification.info(sender, "领地缓存已重新加载");
|
||||||
|
});
|
||||||
|
Dominion.scheduler.async.runNow(Dominion.instance, ScheduledTask -> {
|
||||||
Notification.info(sender, "正在从数据库重新加载玩家权限缓存...");
|
Notification.info(sender, "正在从数据库重新加载玩家权限缓存...");
|
||||||
Cache.instance.loadPlayerPrivileges();
|
Cache.instance.loadPlayerPrivileges();
|
||||||
Notification.info(sender, "缓存刷新完成");
|
Notification.info(sender, "玩家权限缓存已重新加载");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void exportMca(CommandSender sender, String[] args) {
|
||||||
|
if (notOpOrConsole(sender)) return;
|
||||||
|
Dominion.scheduler.async.runNow(Dominion.instance, ScheduledTask -> {
|
||||||
|
Notification.info(sender, "正在导出拥有领地的MCA文件列表...");
|
||||||
|
Map<String, List<String>> mca_cords = new HashMap<>();
|
||||||
|
List<DominionDTO> doms = Cache.instance.getDominions();
|
||||||
|
for (DominionDTO dom : doms) {
|
||||||
|
if (!mca_cords.containsKey(dom.getWorld())) {
|
||||||
|
mca_cords.put(dom.getWorld(), new ArrayList<>());
|
||||||
|
}
|
||||||
|
Integer world_x1 = dom.getX1();
|
||||||
|
Integer world_x2 = dom.getX2();
|
||||||
|
Integer world_z1 = dom.getZ1();
|
||||||
|
Integer world_z2 = dom.getZ2();
|
||||||
|
int mca_x1 = world_x1 / 512 - 1;
|
||||||
|
int mca_x2 = world_x2 / 512 + 1;
|
||||||
|
int mca_z1 = world_z1 / 512 - 1;
|
||||||
|
int mca_z2 = world_z2 / 512 + 1;
|
||||||
|
for (int x = mca_x1; x <= mca_x2; x++) {
|
||||||
|
for (int z = mca_z1; z <= mca_z2; z++) {
|
||||||
|
String file_name = "r." + x + "." + z + ".mca";
|
||||||
|
if (mca_cords.get(dom.getWorld()).contains(file_name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mca_cords.get(dom.getWorld()).add(file_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File folder = new File(Dominion.instance.getDataFolder(), "ExportedMCAList");
|
||||||
|
if (!folder.exists()) {
|
||||||
|
boolean success = folder.mkdirs();
|
||||||
|
if (!success) {
|
||||||
|
Notification.error(sender, "创建导出文件夹失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String world : mca_cords.keySet()) {
|
||||||
|
File file = new File(folder, world + ".txt");
|
||||||
|
Notification.info(sender, "正在导出 " + world + " 的MCA文件列表...");
|
||||||
|
try {
|
||||||
|
if (file.exists()) {
|
||||||
|
boolean success = file.delete();
|
||||||
|
if (!success) {
|
||||||
|
Notification.error(sender, "删除 " + world + " 的MCA文件列表失败");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean success = file.createNewFile();
|
||||||
|
if (!success) {
|
||||||
|
Notification.error(sender, "创建 " + world + " 的MCA文件列表失败");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
List<String> cords = mca_cords.get(world);
|
||||||
|
for (String cord : cords) {
|
||||||
|
XLogger.debug("正在写入 " + cord + "...");
|
||||||
|
try {
|
||||||
|
java.nio.file.Files.write(file.toPath(), (cord + "\n").getBytes(), java.nio.file.StandardOpenOption.APPEND);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Notification.error(sender, "写入 " + cord + " 失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Notification.error(sender, "导出 " + world + " 的MCA文件列表失败");
|
||||||
|
Notification.error(sender, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BlueMapConnect.renderMCA(mca_cords);
|
||||||
|
Notification.info(sender, "MCA文件列表已导出到 " + folder.getAbsolutePath());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import org.bukkit.event.block.BlockFromToEvent;
|
|||||||
import org.bukkit.event.block.BlockIgniteEvent;
|
import org.bukkit.event.block.BlockIgniteEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityDropItemEvent;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
|
|||||||
import cn.lunadeer.dominion.utils.Notification;
|
import cn.lunadeer.dominion.utils.Notification;
|
||||||
import io.papermc.paper.event.entity.EntityDyeEvent;
|
import io.papermc.paper.event.entity.EntityDyeEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -23,7 +22,6 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.spigotmc.event.entity.EntityMountEvent;
|
import org.spigotmc.event.entity.EntityMountEvent;
|
||||||
|
|
||||||
public class PlayerEvents implements Listener {
|
public class PlayerEvents implements Listener {
|
||||||
|
@ -10,6 +10,7 @@ public class Notification {
|
|||||||
private static final Style i_style = Style.style(TextColor.color(139, 255, 123));
|
private static final Style i_style = Style.style(TextColor.color(139, 255, 123));
|
||||||
private static final Style w_style = Style.style(TextColor.color(255, 185, 69));
|
private static final Style w_style = Style.style(TextColor.color(255, 185, 69));
|
||||||
private static final Style e_style = Style.style(TextColor.color(255, 96, 72));
|
private static final Style e_style = Style.style(TextColor.color(255, 96, 72));
|
||||||
|
private static final Style d_style = Style.style(TextColor.color(0, 255, 255));
|
||||||
|
|
||||||
private static final String prefix = "[Dominion] ";
|
private static final String prefix = "[Dominion] ";
|
||||||
|
|
||||||
|
15
src/main/java/cn/lunadeer/dominion/utils/Scheduler.java
Normal file
15
src/main/java/cn/lunadeer/dominion/utils/Scheduler.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package cn.lunadeer.dominion.utils;
|
||||||
|
|
||||||
|
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
|
||||||
|
import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class Scheduler {
|
||||||
|
public Scheduler(JavaPlugin plugin) {
|
||||||
|
region = plugin.getServer().getGlobalRegionScheduler();
|
||||||
|
async = plugin.getServer().getAsyncScheduler();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalRegionScheduler region;
|
||||||
|
public AsyncScheduler async;
|
||||||
|
}
|
@ -1,11 +1,9 @@
|
|||||||
package cn.lunadeer.dominion.utils;
|
package cn.lunadeer.dominion.utils;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class Time {
|
public class Time {
|
||||||
|
|
||||||
@ -39,23 +37,4 @@ public class Time {
|
|||||||
if (IS_FOLIA == null) IS_FOLIA = tryFolia();
|
if (IS_FOLIA == null) IS_FOLIA = tryFolia();
|
||||||
return IS_FOLIA;
|
return IS_FOLIA;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时异步任务
|
|
||||||
*
|
|
||||||
* @param plugin 插件
|
|
||||||
* @param runnable 任务
|
|
||||||
* @param ticks 间隔
|
|
||||||
*/
|
|
||||||
public static void runAtFixedRateAsync(Plugin plugin, Runnable runnable, int ticks) {
|
|
||||||
if (isFolia())
|
|
||||||
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, (task) -> runnable.run(), ticks / 20, ticks / 20, TimeUnit.SECONDS);
|
|
||||||
else Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, ticks, ticks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void runLater(Plugin plugin, Runnable runnable, int ticks) {
|
|
||||||
if (isFolia())
|
|
||||||
Bukkit.getAsyncScheduler().runDelayed(plugin, (task) -> runnable.run(), ticks / 20, TimeUnit.SECONDS);
|
|
||||||
else Bukkit.getScheduler().runTaskLater(plugin, runnable, ticks);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user