-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd9664f
commit d55b46f
Showing
11 changed files
with
183 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,106 @@ | ||
package cn.lunadeer.dominion.commands; | ||
|
||
import cn.lunadeer.dominion.BlueMapConnect; | ||
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.XLogger; | ||
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; | ||
|
||
public class Operator { | ||
|
||
public static void reloadCache(CommandSender sender, String[] args){ | ||
public static void reloadCache(CommandSender sender, String[] args) { | ||
if (notOpOrConsole(sender)) return; | ||
Dominion.scheduler.async.runNow(Dominion.instance, ScheduledTask -> { | ||
Notification.info(sender, "正在从数据库重新加载领地缓存..."); | ||
Cache.instance.loadDominions(); | ||
Notification.info(sender, "领地缓存已重新加载"); | ||
}); | ||
Dominion.scheduler.async.runNow(Dominion.instance, ScheduledTask -> { | ||
Notification.info(sender, "正在从数据库重新加载玩家权限缓存..."); | ||
Cache.instance.loadPlayerPrivileges(); | ||
Notification.info(sender, "玩家权限缓存已重新加载"); | ||
}); | ||
} | ||
|
||
public static void exportMca(CommandSender sender, String[] args) { | ||
if (notOpOrConsole(sender)) return; | ||
Notification.info(sender, "正在从数据库重新加载领地缓存..."); | ||
Cache.instance.loadDominions(); | ||
Notification.info(sender, "正在从数据库重新加载玩家权限缓存..."); | ||
Cache.instance.loadPlayerPrivileges(); | ||
Notification.info(sender, "缓存刷新完成"); | ||
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()); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters