This commit is contained in:
zhangyuheng 2024-01-23 11:40:46 +08:00
commit fe57c76272
9 changed files with 438 additions and 0 deletions

113
.gitignore vendored Normal file
View File

@ -0,0 +1,113 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
# Common working directory
run/

44
README.md Normal file
View File

@ -0,0 +1,44 @@
# BetterChunkUnload
## 自定义区块卸载规则
## 说明
## 功能介绍
## 支持版本
- 1.20.1+ (Paper、Folia)
## 安装方法
1. 将插件放入服务器的 `plugins` 目录下
2. 重启服务器
3. 在 `plugins/BetterChunkUnload/config.yml` 中配置
4. 重启服务器
## 使用方法
## 管理员指南
## 指令
### 玩家指令
### 管理员指令
## 配置文件参考
```yaml
```
## TODO

75
pom.xml Normal file
View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.lunadeer</groupId>
<artifactId>BetterChunkUnload</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>BetterChunkUnload</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,35 @@
package cn.lunadeer.betterchunkunload;
import cn.lunadeer.betterchunkunload.utils.ConfigManager;
import cn.lunadeer.betterchunkunload.utils.XLogger;
import org.bukkit.plugin.java.JavaPlugin;
public final class BetterChunkUnload extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
instance = this;
config = new ConfigManager(instance);
// http://patorjk.com/software/taag/#p=display&f=Big&t=BetterChunkUnload
XLogger.info(" ____ _ _ _____ _ _ _ _ _ _");
XLogger.info(" | _ \\ | | | | / ____| | | | | | | | | | | |");
XLogger.info(" | |_) | ___| |_| |_ ___ _ __| | | |__ _ _ _ __ | | _| | | |_ __ | | ___ __ _ __| |");
XLogger.info(" | _ < / _ \\ __| __/ _ \\ '__| | | '_ \\| | | | '_ \\| |/ / | | | '_ \\| |/ _ \\ / _` |/ _` |");
XLogger.info(" | |_) | __/ |_| || __/ | | |____| | | | |_| | | | | <| |__| | | | | | (_) | (_| | (_| |");
XLogger.info(" |____/ \\___|\\__|\\__\\___|_| \\_____|_| |_|\\__,_|_| |_|_|\\_\\\\____/|_| |_|_|\\___/ \\__,_|\\__,_|");
XLogger.info(" ");
XLogger.info("BetterChunkUnload 已加载");
XLogger.info("版本: " + getPluginMeta().getVersion());
XLogger.info(" ");
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
public static BetterChunkUnload instance;
public static ConfigManager config;
}

View File

@ -0,0 +1,37 @@
package cn.lunadeer.betterchunkunload.utils;
import cn.lunadeer.betterchunkunload.BetterChunkUnload;
import org.bukkit.configuration.file.FileConfiguration;
public class ConfigManager {
public ConfigManager(BetterChunkUnload plugin) {
_plugin = plugin;
_plugin.saveDefaultConfig();
reload();
_plugin.saveConfig();
}
public void reload() {
_plugin.reloadConfig();
_file = _plugin.getConfig();
_debug = _file.getBoolean("Debug", false);
}
public Boolean isDebug() {
return _debug;
}
public void setDebug(Boolean debug) {
_debug = debug;
_file.set("Debug", debug);
_plugin.saveConfig();
}
private final BetterChunkUnload _plugin;
private FileConfiguration _file;
private Boolean _debug;
}

View File

@ -0,0 +1,72 @@
package cn.lunadeer.betterchunkunload.utils;
import cn.lunadeer.betterchunkunload.BetterChunkUnload;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.betterchunkunload.utils.XLogger.*;
public class Notification {
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 e_style = Style.style(TextColor.color(255, 96, 72));
private static final String prefix = "[BetterChunkUnload] ";
public static void info(Player player, String msg) {
player.sendMessage(Component.text(prefix + msg, i_style));
}
public static void warn(Player player, String msg) {
player.sendMessage(Component.text(prefix + msg, w_style));
}
public static void error(Player player, String msg) {
player.sendMessage(Component.text(prefix + msg, e_style));
}
public static void info(CommandSender sender, String msg) {
sender.sendMessage(Component.text(prefix + msg, i_style));
}
public static void warn(CommandSender sender, String msg) {
sender.sendMessage(Component.text(prefix + msg, w_style));
}
public static void error(CommandSender sender, String msg) {
sender.sendMessage(Component.text(prefix + msg, e_style));
}
public static void info(Player player, Component msg) {
player.sendMessage(Component.text(prefix, i_style).append(msg));
if (BetterChunkUnload.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的提示 | " + msg);
}
public static void warn(Player player, Component msg) {
player.sendMessage(Component.text(prefix, w_style).append(msg));
if (BetterChunkUnload.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的警告 | " + msg);
}
public static void error(Player player, Component msg) {
player.sendMessage(Component.text(prefix, e_style).append(msg));
if (BetterChunkUnload.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的报错 | " + msg);
}
public static void info(CommandSender player, Component msg) {
player.sendMessage(Component.text(prefix, i_style).append(msg));
}
public static void warn(CommandSender player, Component msg) {
player.sendMessage(Component.text(prefix, w_style).append(msg));
}
public static void error(CommandSender player, Component msg) {
player.sendMessage(Component.text(prefix, e_style).append(msg));
}
}

View File

@ -0,0 +1,56 @@
package cn.lunadeer.betterchunkunload.utils;
import cn.lunadeer.betterchunkunload.BetterChunkUnload;
import org.bukkit.entity.Player;
import java.util.logging.Logger;
public class XLogger {
private static final BetterChunkUnload _plugin = BetterChunkUnload.instance;
private static final Logger _logger = _plugin.getLogger();
private static final String prefix = "[BetterChunkUnload] ";
public static void info(Player player, String message) {
Notification.info(player, prefix + "I | " + message);
if (BetterChunkUnload.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的信息 | " + message);
}
public static void info(String message) {
_logger.info(" I | " + message);
}
public static void warn(Player player, String message) {
Notification.warn(player, prefix + "W | " + message);
if (BetterChunkUnload.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的警告 | " + message);
}
public static void warn(String message) {
_logger.info(" W | " + message);
}
public static void err(Player player, String message) {
Notification.error(player, prefix + "E | " + message);
if (BetterChunkUnload.config.isDebug())
debug("来自玩家[ " + player.getName() + " ] 的报错 | " + message);
}
public static void err(String message) {
_logger.info(" E | " + message);
}
public static void debug(Player player, String message) {
if (!BetterChunkUnload.config.isDebug()) return;
if (player.isOp())
Notification.info(player, prefix + "D | " + message);
else
debug("来自玩家[ " + player.getName() + " ] 的调试 | " + message);
}
public static void debug(String message) {
if (!BetterChunkUnload.config.isDebug()) return;
_logger.info(" D | " + message);
}
}

View File

View File

@ -0,0 +1,6 @@
name: BetterChunkUnload
version: '${project.version}'
main: cn.lunadeer.betterchunkunload.BetterChunkUnload
api-version: '1.20'
load: STARTUP
folia-supported: true