1
mirror of https://github.com/CarmJos/EasyPlugin.git synced 2026-06-05 00:58:17 +08:00

Compare commits

...

22 Commits

Author SHA1 Message Date
carm 4fa3ffaa93 修改赞助配置 2022-01-13 16:01:04 +08:00
carm 6ba1be457f [v1.3.2] 修复部署 2022-01-13 16:00:08 +08:00
carm f170d654d6 [v1.3.1] [A] 更新EasySQL版本 2022-01-13 15:28:29 +08:00
carm ff4da6b73e [v1.3.1] [A] 添加PagedGUI接口 2022-01-13 02:00:32 +08:00
carm d39951bf65 修改Javadoc部署密钥 2022-01-09 13:26:28 +08:00
carm 90a276c1c1 修改库地址 2022-01-09 13:25:49 +08:00
carm f15e0a5bec [v1.3.0] 版本更新
- [U] 添加 MessagesInitializer 与 MessagesConfig 等相关消息配置,用于快捷创建消息静态类进行消文本消息的处理。
2022-01-09 13:13:30 +08:00
carm 2ac6fc1485 修改依赖版本 2022-01-08 17:39:34 +08:00
carm 7701efa34f 修改Javadoc路径 2022-01-08 02:34:34 +08:00
carm ff25446fd4 测试Javadoc部署 2022-01-08 02:32:05 +08:00
carm 40b66740e0 测试Javadoc部署 2022-01-08 02:31:44 +08:00
carm af79d41cf6 测试Javadoc部署 2022-01-08 02:26:32 +08:00
carm 6fad72c44f 测试Javadoc部署 2022-01-08 02:20:17 +08:00
carm a7ed8bc4fd 测试Javadoc部署 2022-01-08 02:13:02 +08:00
carm b18e6ec3d3 测试Javadoc部署 2022-01-08 02:07:54 +08:00
carm 3d9748c48e 测试Javadoc部署 2022-01-08 02:04:10 +08:00
carm aaba1a8097 测试Javadoc部署 2022-01-08 02:01:28 +08:00
carm 47966b0be3 测试Javadoc部署 2022-01-08 01:48:08 +08:00
carm b1b6b95a07 测试Javadoc部署 2022-01-08 01:47:49 +08:00
carm 55263a4d5b 添加赞助方式 2022-01-08 01:37:23 +08:00
carm d5632d371b 测试javadoc部署 2022-01-08 01:35:16 +08:00
carm 43643ba423 [v1.2.0] 版本更新
- [U] 采用新版本EasySQL,快捷操作数据库,优雅永不过时。
- [A] 针对DatabaseTable添加数个快捷操作的方式。
2022-01-08 01:11:23 +08:00
30 changed files with 1083 additions and 234 deletions
+38
View File
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EasyPlugin Javadocs</title>
<style>
.container {
width: 60%;
margin: 10% auto 0;
background-color: #f0f0f0;
padding: 2% 5%;
border-radius: 10px
}
ul {
padding-left: 20px;
}
ul li {
line-height: 2.3
}
a {
color: #20a53a
}
</style>
</head>
<body>
<div class="container">
<h1>EasyPlugin Javadocs</h1>
<ul>
<li><a href="main/index.html">EasyPlugin-Main</a></li>
<li><a href="command/index.html">EasyPlugin-Command</a></li>
<li><a href="configuration/index.html">EasyPlugin-Configuration</a></li>
</ul>
</div>
</body>
</html>
+2
View File
@@ -0,0 +1,2 @@
#github: [ CarmJos ]
custom: [ 'https://donate.carm.cc' ]
+7 -6
View File
@@ -23,19 +23,19 @@ jobs:
cache: maven
java-version: '11'
distribution: 'adopt'
server-id: github
server-username: MAVEN_USERNAME
server-password: MAVEN_TOKEN
- name: Generate docs
run: mvn clean package -DskipTests
run: mvn javadoc:javadoc -DskipTests
env:
MAVEN_USERNAME: ${{ github.repository_owner }}
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Copy to Location
run: |
rm -rf docs
mkdir -vp docs
cp -vrf EasyPlugin-api/target/apidocs/* docs/
cp -vrf .documentation/JAVADOC-README.md docs/README.md
bash .scripts/copy-javadoc.sh
- name: Generate the sitemap
id: sitemap
@@ -49,6 +49,7 @@ jobs:
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
ls -l docs
- name: Configure Git
env:
+21
View File
@@ -0,0 +1,21 @@
rm -rf docs
mkdir -vp docs
DOC_URL="target/site/apidocs"
for FILE in easyplugin-*; do
if test -e "$FILE/$DOC_URL"; then
MODULE_FILE="docs/${FILE:11}/"
mkdir -vp "$MODULE_FILE"
cp -vrf "$FILE"/"$DOC_URL"/* "$MODULE_FILE"
fi
done
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
cp -vrf .documentation/javadoc/index.html docs/index.html
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+74 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -18,11 +18,70 @@
<artifactId>easyplugin-bom</artifactId>
<packaging>pom</packaging>
<name>00-EasyPlugin-Bom</name>
<description>轻松插件汇总导入模块,允许快捷导入相关的接口并避免版本不一致问题。</description>
<url>https://github.com/CarmJos/EasyPlugin</url>
<developers>
<developer>
<id>CarmJos</id>
<name>Carm Jos</name>
<email>carm@carm.cc</email>
<url>https://www.carm.cc</url>
</developer>
</developers>
<licenses>
<license>
<name>The MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
</issueManagement>
<ciManagement>
<system>GitHub Actions</system>
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
</ciManagement>
<distributionManagement>
<downloadUrl>https://github.com/CarmJos/EasyPlugin/releases</downloadUrl>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>carm-repo</id>
<name>Carm's Repo</name>
<url>https://repo.carm.cc/repository/maven-public/</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/CarmJos/*</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
@@ -103,5 +162,18 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -14,116 +14,115 @@ import java.util.function.Supplier;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class FileConfig {
public static Supplier<FileConfig> pluginConfiguration = null;
public static Supplier<FileConfig> messageConfiguration = null;
public static Supplier<FileConfig> pluginConfiguration = null;
public static Supplier<FileConfig> messageConfiguration = null;
@Nullable
public static FileConfig getPluginConfiguration() {
return pluginConfiguration == null ? null : pluginConfiguration.get();
}
@Nullable
public static FileConfig getPluginConfiguration() {
return pluginConfiguration == null ? null : pluginConfiguration.get();
}
@Nullable
public static FileConfig getMessageConfiguration() {
return messageConfiguration == null ? null : messageConfiguration.get();
}
@Nullable
public static FileConfig getMessageConfiguration() {
return messageConfiguration == null ? null : messageConfiguration.get();
}
private long updateTime;
protected long updateTime;
private final JavaPlugin plugin;
private final File fileFolder;
private final String fileName;
private final String resourcePath;
protected final JavaPlugin plugin;
protected final File fileFolder;
protected final String fileName;
protected final String resourcePath;
private File file;
private FileConfiguration config;
protected File file;
protected FileConfiguration config;
public FileConfig(@NotNull JavaPlugin plugin) throws IOException {
this(plugin, "config.yml");
}
public FileConfig(@NotNull JavaPlugin plugin) throws IOException {
this(plugin, "config.yml");
}
public FileConfig(@NotNull JavaPlugin plugin,
@NotNull String fileName) throws IOException {
this(plugin, fileName, fileName);
}
public FileConfig(@NotNull JavaPlugin plugin,
@NotNull String fileName) throws IOException {
this(plugin, fileName, fileName);
}
public FileConfig(@NotNull JavaPlugin plugin, @NotNull String resourcePath,
@NotNull String fileName) throws IOException {
this(plugin, resourcePath, plugin.getDataFolder(), fileName);
}
public FileConfig(@NotNull JavaPlugin plugin, @NotNull String resourcePath,
@NotNull String fileName) throws IOException {
this(plugin, resourcePath, plugin.getDataFolder(), fileName);
}
public FileConfig(@NotNull JavaPlugin plugin, @NotNull String resourcePath,
@NotNull File fileFolder, @NotNull String fileName) throws IOException {
this.plugin = plugin;
this.resourcePath = resourcePath;
this.fileFolder = fileFolder;
this.fileName = fileName;
public FileConfig(@NotNull JavaPlugin plugin, @NotNull String resourcePath,
@NotNull File fileFolder, @NotNull String fileName) throws IOException {
this.plugin = plugin;
this.resourcePath = resourcePath;
this.fileFolder = fileFolder;
this.fileName = fileName;
initFile();
}
initFile();
}
protected void initFile() throws IOException {
if (!getFileFolder().exists()) getFileFolder().mkdirs();
this.file = new File(getFileFolder(), fileName);
private void initFile() throws IOException {
if (!getFileFolder().exists()) getFileFolder().mkdirs();
this.file = new File(getFileFolder(), fileName);
if (!file.exists()) {
InputStream resourceStream = plugin.getResource(resourcePath);
if (resourceStream == null) {
throw new IOException("The resource " + resourcePath + " cannot find in " + plugin.getName() + " !");
}
if (!file.exists()) {
InputStream resourceStream = plugin.getResource(resourcePath);
if (resourceStream == null) {
throw new IOException("The resource " + resourcePath + " cannot find in " + plugin.getName() + " !");
}
OutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[1024];
OutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int readBytes;
while ((readBytes = resourceStream.read(buffer)) > 0) {
out.write(buffer, 0, readBytes);
}
int readBytes;
while ((readBytes = resourceStream.read(buffer)) > 0) {
out.write(buffer, 0, readBytes);
}
out.close();
resourceStream.close();
out.close();
resourceStream.close();
ConfigUpdater.update(plugin, resourcePath, file); // Save comments
}
ConfigUpdater.update(plugin, resourcePath, file); // Save comments
}
this.updateTime = System.currentTimeMillis();
this.config = YamlConfiguration.loadConfiguration(this.file);
}
this.updateTime = System.currentTimeMillis();
this.config = YamlConfiguration.loadConfiguration(this.file);
}
public File getFileFolder() {
return fileFolder;
}
public File getFileFolder() {
return fileFolder;
}
public File getFile() {
return file;
}
public File getFile() {
return file;
}
public FileConfiguration getConfig() {
return config;
}
public FileConfiguration getConfig() {
return config;
}
public JavaPlugin getPlugin() {
return plugin;
}
public JavaPlugin getPlugin() {
return plugin;
}
public void save() throws IOException {
getConfig().save(getFile());
ConfigUpdater.update(plugin, resourcePath, file); // Save comments
}
public void save() throws IOException {
getConfig().save(getFile());
ConfigUpdater.update(plugin, resourcePath, file); // Save comments
}
public void reload() throws IOException {
this.updateTime = System.currentTimeMillis();
if (getFile().exists()) {
this.config = YamlConfiguration.loadConfiguration(getFile());
} else {
initFile();
}
}
public void reload() throws IOException {
this.updateTime = System.currentTimeMillis();
if (getFile().exists()) {
this.config = YamlConfiguration.loadConfiguration(getFile());
} else {
initFile();
}
}
public long getUpdateTime() {
return updateTime;
}
public long getUpdateTime() {
return updateTime;
}
public boolean isExpired(long time) {
return getUpdateTime() > time;
}
public boolean isExpired(long time) {
return getUpdateTime() > time;
}
}
@@ -0,0 +1,105 @@
package cc.carm.lib.easyplugin.configuration.language;
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
import cc.carm.lib.easyplugin.utils.ColorParser;
import cc.carm.lib.easyplugin.utils.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
public class EasyMessage {
@Nullable ConfigValue<String> configValue;
@Nullable String defaultValue;
@Nullable String[] messageParams;
public EasyMessage() {
this(null);
}
public EasyMessage(@Nullable String defaultValue) {
this(defaultValue, null);
}
public EasyMessage(@Nullable String defaultValue, @Nullable String[] messageParams) {
this.defaultValue = defaultValue;
this.messageParams = messageParams;
}
public void initialize(@NotNull FileConfig sourceConfig, @NotNull String sectionName) {
this.configValue = new ConfigValue<>(sourceConfig, sectionName, String.class, getDefaultValue());
}
private @Nullable String getDefaultValue() {
return defaultValue;
}
private @Nullable String[] getMessageParams() {
return messageParams;
}
private @NotNull String getDefaultMessages() {
if (getDefaultValue() == null) return "";
else return getDefaultValue();
}
private @NotNull String getMessages() {
if (configValue == null) {
return getDefaultMessages();
} else {
return configValue.get();
}
}
public @NotNull String get(@Nullable CommandSender sender) {
return get(sender, null);
}
public @NotNull String get(@Nullable CommandSender sender, @Nullable Object[] values) {
return get(sender, getMessageParams(), values);
}
public @NotNull String get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
if (sender == null) return getMessages();
if (params == null || values == null) {
return ColorParser.parse(MessageUtils.setPlaceholders(sender, getMessages()));
} else {
return ColorParser.parse(MessageUtils.setPlaceholders(sender, getMessages(), params, values));
}
}
public void send(@Nullable CommandSender sender) {
send(sender, null);
}
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
send(sender, getMessageParams(), values);
}
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
if (params == null || values == null) {
MessageUtils.sendWithPlaceholders(sender, getMessages());
} else {
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(getMessages()), params, values);
}
}
public void sendToAll() {
sendToAll(null);
}
public void sendToAll(@Nullable Object[] values) {
sendToAll(messageParams, values);
}
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
}
}
@@ -0,0 +1,110 @@
package cc.carm.lib.easyplugin.configuration.language;
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
import cc.carm.lib.easyplugin.utils.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class EasyMessageList {
@Nullable ConfigValueList<String> configValue;
@Nullable String[] defaultValue;
@Nullable String[] messageParams;
public EasyMessageList() {
this((String[]) null);
}
public EasyMessageList(@Nullable String... defaultValue) {
this(defaultValue, null);
}
public EasyMessageList(@Nullable String[] defaultValue,
@Nullable String[] messageParams) {
this.defaultValue = defaultValue;
this.messageParams = messageParams;
}
public void initialize(FileConfig sourceConfig, String sectionName) {
configValue = new ConfigValueList<>(sourceConfig, sectionName, String.class, getDefaultValue());
}
private @Nullable String[] getDefaultValue() {
return defaultValue;
}
@Unmodifiable
private @NotNull List<String> getDefaultMessages() {
if (getDefaultValue() == null) return new ArrayList<>();
else return Arrays.asList(getDefaultValue());
}
private @Nullable String[] getMessageParams() {
return messageParams;
}
private @NotNull List<String> getMessages() {
if (configValue == null) {
return getDefaultMessages();
} else {
return configValue.get();
}
}
public @NotNull List<String> get(@Nullable CommandSender sender) {
return get(sender, null);
}
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable Object[] values) {
return get(sender, getMessageParams(), values);
}
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
if (sender == null) return getMessages();
if (params == null || values == null) {
return MessageUtils.setPlaceholders(sender, getMessages());
} else {
return MessageUtils.setPlaceholders(sender, getMessages(), params, values);
}
}
public void send(@Nullable CommandSender sender) {
send(sender, null);
}
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
send(sender, getMessageParams(), values);
}
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
if (params == null || values == null) {
MessageUtils.sendWithPlaceholders(sender, getMessages());
} else {
MessageUtils.sendWithPlaceholders(sender, getMessages(), params, values);
}
}
public void sendToAll() {
sendToAll(null);
}
public void sendToAll(@Nullable Object[] values) {
sendToAll(messageParams, values);
}
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
}
}
@@ -0,0 +1,39 @@
package cc.carm.lib.easyplugin.configuration.language;
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class MessagesConfig extends FileConfig {
public MessagesConfig(@NotNull JavaPlugin plugin) throws IOException {
this(plugin, "messages.yml");
}
public MessagesConfig(@NotNull JavaPlugin plugin, @NotNull String fileName) throws IOException {
this(plugin, plugin.getDataFolder(), fileName);
}
public MessagesConfig(@NotNull JavaPlugin plugin, @NotNull File fileFolder, @NotNull String fileName) throws IOException {
super(plugin, fileName, fileFolder, fileName);
}
@Override
public void initFile() throws IOException {
if (!getFileFolder().exists()) getFileFolder().mkdirs();
this.file = new File(getFileFolder(), fileName);
if (!file.exists()) file.createNewFile();
this.config = YamlConfiguration.loadConfiguration(this.file);
}
@Override
public void save() throws IOException {
getConfig().save(getFile());
}
}
@@ -0,0 +1,100 @@
package cc.carm.lib.easyplugin.configuration.language;
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
public class MessagesInitializer {
private MessagesInitializer() {
// 静态方法类,不应当实例化。
}
public static void initialize(FileConfig source, Class<? extends MessagesRoot> rootClazz) {
initialize(source, rootClazz, true);
}
public static void initialize(FileConfig source, Class<? extends MessagesRoot> rootClazz, boolean saveDefault) {
MessagesSection sectionAnnotation = rootClazz.getAnnotation(MessagesSection.class);
String rootSection = null;
if (sectionAnnotation != null && sectionAnnotation.value().length() > 1) {
rootSection = sectionAnnotation.value();
}
for (Class<?> innerClass : rootClazz.getDeclaredClasses()) {
initSection(source, rootSection, innerClass, saveDefault);
}
for (Field field : rootClazz.getFields()) {
initMessage(source, rootSection, rootClazz, field, saveDefault);
}
if (saveDefault) {
try {
source.save();
} catch (IOException ignore) {
}
}
}
private static void initSection(FileConfig source, String parentSection, Class<?> clazz, boolean saveDefault) {
if (!Modifier.isStatic(clazz.getModifiers()) || !Modifier.isPublic(clazz.getModifiers())) return;
String section = getSection(clazz.getSimpleName(), parentSection, clazz.getAnnotation(MessagesSection.class));
for (Class<?> innerClass : clazz.getDeclaredClasses()) initSection(source, section, innerClass, saveDefault);
for (Field field : clazz.getFields()) initMessage(source, section, clazz, field, saveDefault);
}
private static void initMessage(FileConfig source, String parentSection, Class<?> clazz, Field field, boolean saveDefault) {
try {
String section = getSection(field.getName(), parentSection, field.getAnnotation(MessagesSection.class));
Object object = field.get(clazz);
if (object instanceof EasyMessage) {
EasyMessage message = ((EasyMessage) object);
if (saveDefault && message.defaultValue != null && !source.getConfig().contains(section)) {
source.getConfig().set(section, message.defaultValue);
}
message.initialize(source, section);
} else if (object instanceof EasyMessageList) {
EasyMessageList messageList = ((EasyMessageList) object);
if (saveDefault && messageList.defaultValue != null && !source.getConfig().contains(section)) {
source.getConfig().set(section, Arrays.asList(messageList.defaultValue));
}
messageList.initialize(source, section);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private static String getSection(@NotNull String name,
@Nullable String parentSection,
@Nullable MessagesSection sectionAnnotation) {
String parent = parentSection != null ? parentSection + "." : "";
if (sectionAnnotation != null && sectionAnnotation.value().length() > 0) {
return parent + sectionAnnotation.value();
} else {
return parent + getSectionName(name);
}
}
private static String getSectionName(String codeName) {
return codeName.toLowerCase().replace("_", "-");
}
}
@@ -0,0 +1,5 @@
package cc.carm.lib.easyplugin.configuration.language;
public abstract class MessagesRoot {
}
@@ -0,0 +1,14 @@
package cc.carm.lib.easyplugin.configuration.language;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MessagesSection {
String value() default "";
}
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -54,7 +54,7 @@
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-beecp</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -25,7 +25,6 @@ public class GUI {
public static void initialize(JavaPlugin plugin) {
GUI.plugin = plugin;
}
public static JavaPlugin getPlugin() {
@@ -36,8 +35,8 @@ public class GUI {
return openedGUIs;
}
GUIType type;
String name;
protected GUIType type;
protected String name;
public HashMap<Integer, GUIItem> items;
public Inventory inv;
@@ -0,0 +1,96 @@
package cc.carm.lib.easyplugin.gui.paged;
import cc.carm.lib.easyplugin.gui.GUIItem;
import cc.carm.lib.easyplugin.gui.GUIType;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.function.Function;
public class AutoPagedGUI extends CommonPagedGUI {
public static Function<Player, ItemStack> defaultPreviousPage = null;
public static Function<Player, ItemStack> defaultNextPage = null;
ItemStack previousPageUI;
ItemStack nextPageUI;
int previousPageSlot = -1;
int nextPageSlot = -1;
public AutoPagedGUI(GUIType type, String name, int[] range) {
super(type, name, range);
}
public AutoPagedGUI(GUIType type, String name, int a, int b) {
super(type, name, a, b);
}
public void setPreviousPageUI(ItemStack lastPageUI) {
this.previousPageUI = lastPageUI;
}
public void setNextPageUI(ItemStack nextPageUI) {
this.nextPageUI = nextPageUI;
}
public void setPreviousPageSlot(int slot) {
this.previousPageSlot = slot;
}
public void setNextPageSlot(int slot) {
this.nextPageSlot = slot;
}
@Override
public void openGUI(Player user) {
if (previousPageSlot >= 0) {
if (hasPreviousPage()) {
setItem(previousPageSlot, new GUIItem(
previousPageUI == null ? getDefaultPreviousPage(user) : previousPageUI) {
@Override
public void onClick(ClickType type) {
if (type == ClickType.RIGHT) {
goFirstPage();
} else {
goPreviousPage();
}
openGUI(user);
}
});
} else {
setItem(previousPageSlot, null);
}
}
if (nextPageSlot >= 0) {
if (hasNextPage()) {
setItem(nextPageSlot, new GUIItem(
nextPageUI == null ? getDefaultNextPage(user) : nextPageUI) {
@Override
public void onClick(ClickType type) {
if (type == ClickType.RIGHT) {
goLastPage();
} else {
goNextPage();
}
openGUI(user);
}
});
} else {
setItem(nextPageSlot, null);
}
}
super.openGUI(user);
}
private static ItemStack getDefaultNextPage(Player player) {
return defaultNextPage != null ? defaultNextPage.apply(player) : null;
}
private static ItemStack getDefaultPreviousPage(Player player) {
return defaultPreviousPage != null ? defaultPreviousPage.apply(player) : null;
}
}
@@ -0,0 +1,162 @@
package cc.carm.lib.easyplugin.gui.paged;
import cc.carm.lib.easyplugin.gui.GUIItem;
import cc.carm.lib.easyplugin.gui.GUIType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CommonPagedGUI extends PagedGUI {
private int[] range;
private CommonPagedGUI(GUIType type, String name) {
super(type, name);
}
public CommonPagedGUI(GUIType type, String Name, int a, int b) {
this(type, Name, toRange(type, a, b));
}
public CommonPagedGUI(GUIType type, String Name, int[] range) {
super(type, Name);
Arrays.sort(range);
this.range = range;
}
/*
int[] matrix = new int[]{
0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53
}
*/
private static int[] toRange(GUIType type, int a, int b) {
if (a > b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int lineA = getLine(a);
int columnA = getColumn(a);
int lineB = getLine(b);
int columnB = getColumn(b);
if (lineB > type.getLines())
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
for (int i = 0, l = 0; i < type.getSize(); i++) {
int li = getLine(i);
int ci = getColumn(i);
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
range[l] = i;
l++;
}
}
return range;
}
private static int getLine(int i) {
return i / 9 + 1;
}
private static int getColumn(int i) {
return i % 9 + 1;
}
@Override
public boolean hasPreviousPage() {
return page > 1;
}
@Override
public boolean hasNextPage() {
return page < getLastPageNumber();
}
/**
* 前往第一页
*/
public void goFirstPage() {
if (hasPreviousPage())
this.page = 1;
else
throw new IndexOutOfBoundsException();
}
/**
* 前往最后一页
*/
public void goLastPage() {
if (hasNextPage())
this.page = getLastPageNumber();
else
throw new IndexOutOfBoundsException();
}
/**
* 得到最后一页的页码
*
* @return 最后一页的页码
*/
public int getLastPageNumber() {
return (this.container.size() / range.length) + 1;
}
/**
* 得到第一页的页码
*
* @return 第一页页码(默认为1)
*/
public int getFirstPageNumber() {
return 1;
}
@Override
public void openGUI(Player player) {
if (container.isEmpty()) {
super.openGUI(player);
return;
}
List<GUIItem> list = new ArrayList<>();
int start = (page - 1) * range.length;
for (int i = start; i < start + range.length; i++) {
if (i < container.size()) {
list.add(container.get(i));
} else {
break;
}
}
int i = 0;
Arrays.stream(range).forEach(index -> setItem(index, null));
for (int index : range) {
if (i < list.size()) {
setItem(index, list.get(i));
i++;
} else {
break;
}
}
super.openGUI(player);
}
}
@@ -0,0 +1,79 @@
package cc.carm.lib.easyplugin.gui.paged;
import cc.carm.lib.easyplugin.gui.GUI;
import cc.carm.lib.easyplugin.gui.GUIItem;
import cc.carm.lib.easyplugin.gui.GUIType;
import java.util.ArrayList;
import java.util.List;
public abstract class PagedGUI extends GUI {
List<GUIItem> container = new ArrayList<>();
public int page = 1;
public PagedGUI(GUIType type, String name) {
super(type, name);
}
public int addItem(GUIItem i) {
container.add(i);
return container.size() - 1;
}
/**
* 从GUI中移除一个物品
*
* @param item 物品
*/
public void removeItem(GUIItem item) {
container.remove(item);
}
/**
* 从GUI中移除一个物品
*
* @param slot 物品格子数
*/
public void removeItem(int slot) {
container.remove(slot);
}
public List<GUIItem> getItemsContainer() {
return new ArrayList<>(container);
}
/**
* 前往上一页
*/
public void goPreviousPage() {
if (hasPreviousPage())
page--;
else
throw new IndexOutOfBoundsException();
}
/**
* 前往下一页
*/
public void goNextPage() {
if (hasNextPage())
page++;
else
throw new IndexOutOfBoundsException();
}
/**
* @return 是否有上一页
*/
public abstract boolean hasPreviousPage();
/**
* @return 是否有下一页
*/
public abstract boolean hasNextPage();
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -1,33 +1,44 @@
package cc.carm.lib.easyplugin.utils;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class ColorParser {
public static String parse(String text) {
text = parseHexColor(text);
return parseColor(text);
}
public static String parse(String text) {
text = parseHexColor(text);
return parseColor(text);
}
public static String parseColor(final String text) {
return text.replaceAll("&", "§").replace("§§", "&");
}
public static String[] parse(String... texts) {
return parse(Arrays.asList(texts)).toArray(new String[0]);
}
public static String parseHexColor(String text) {
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
hexColor = hexColor.replace("&", "");
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
for (int i = 1; i < hexColor.length(); i++) {
bukkitColorCode.append('§').append(hexColor.charAt(i));
}
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
matcher.reset(text);
}
return text;
}
public static List<String> parse(List<String> texts) {
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
}
public static String parseColor(final String text) {
return text.replaceAll("&", "§").replace("§§", "&");
}
public static String parseHexColor(String text) {
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
hexColor = hexColor.replace("&", "");
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
for (int i = 1; i < hexColor.length(); i++) {
bukkitColorCode.append('§').append(hexColor.charAt(i));
}
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
matcher.reset(text);
}
return text;
}
}
@@ -14,103 +14,104 @@ import java.util.stream.Collectors;
public class MessageUtils {
public static boolean hasPlaceholderAPI() {
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
}
public static void send(@Nullable CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty() || sender == null) return;
for (String s : messages) {
sender.sendMessage(ColorParser.parse(s));
}
}
public static void send(@Nullable CommandSender sender, String... messages) {
send(sender, Arrays.asList(messages));
}
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
sendWithPlaceholders(sender, Arrays.asList(messages));
}
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty() || sender == null) return;
send(sender, setPlaceholders(sender, messages));
}
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
}
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
}
public static String setPlaceholders(@Nullable CommandSender sender, String message) {
if (message == null || sender == null) return message;
if (hasPlaceholderAPI() && sender instanceof Player) {
return PlaceholderAPI.setPlaceholders((Player) sender, message);
} else {
return message;
}
}
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty() || sender == null) return messages;
if (hasPlaceholderAPI() && sender instanceof Player) {
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
} else {
return messages;
}
}
public static String setPlaceholders(@Nullable CommandSender sender, String message, String[] params, Object[] values) {
return setPlaceholders(sender, setCustomParams(message, params, values));
}
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
return setPlaceholders(sender, setCustomParams(messages, params, values));
}
public static String setCustomParams(String message, String param, Object value) {
return setCustomParams(message, new String[]{param}, new Object[]{value});
}
public static String setCustomParams(String message, String[] params, Object[] values) {
if (params.length != values.length) return message;
HashMap<String, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i++) {
paramsMap.put(params[i], values[i]);
}
return setCustomParams(message, paramsMap);
}
public static boolean hasPlaceholderAPI() {
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
}
public static String setCustomParams(String message, HashMap<String, Object> params) {
String afterMessage = message;
for (Map.Entry<String, Object> entry : params.entrySet()) {
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
}
return afterMessage;
}
public static void send(@Nullable CommandSender sender, String... messages) {
send(sender, Arrays.asList(messages));
}
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
return setCustomParams(messages, new String[]{param}, new Object[]{value});
}
public static void send(@Nullable CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty() || sender == null) return;
for (String s : messages) {
sender.sendMessage(ColorParser.parse(s));
}
}
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
sendWithPlaceholders(sender, Arrays.asList(messages));
}
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
if (params.length != values.length) return messages;
HashMap<String, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i++) {
paramsMap.put(params[i], values[i]);
}
return setCustomParams(messages, paramsMap);
}
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty() || sender == null) return;
send(sender, setPlaceholders(sender, messages));
}
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
}
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
}
public static String setPlaceholders(@Nullable CommandSender sender, String message) {
if (message == null || sender == null) return message;
if (hasPlaceholderAPI() && sender instanceof Player) {
return PlaceholderAPI.setPlaceholders((Player) sender, message);
} else {
return message;
}
}
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty() || sender == null) return messages;
if (hasPlaceholderAPI() && sender instanceof Player) {
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
} else {
return messages;
}
}
public static String setPlaceholders(@Nullable CommandSender sender, String message, String[] params, Object[] values) {
return setPlaceholders(sender, setCustomParams(message, params, values));
}
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
return setPlaceholders(sender, setCustomParams(messages, params, values));
}
public static String setCustomParams(String message, String param, Object value) {
return setCustomParams(message, new String[]{param}, new Object[]{value});
}
public static String setCustomParams(String message, String[] params, Object[] values) {
if (params.length != values.length) return message;
HashMap<String, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i++) {
paramsMap.put(params[i], values[i]);
}
return setCustomParams(message, paramsMap);
}
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
return messages.stream().map(message -> setCustomParams(message, params)).collect(Collectors.toList());
}
public static String setCustomParams(String message, HashMap<String, Object> params) {
String afterMessage = message;
for (Map.Entry<String, Object> entry : params.entrySet()) {
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
}
return afterMessage;
}
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
return setCustomParams(messages, new String[]{param}, new Object[]{value});
}
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
if (params.length != values.length) return messages;
HashMap<String, Object> paramsMap = new HashMap<>();
for (int i = 0; i < params.length; i++) {
paramsMap.put(params[i], values[i]);
}
return setCustomParams(messages, paramsMap);
}
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
return messages.stream().map(message -> setCustomParams(message, params)).collect(Collectors.toList());
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.0</version>
<version>1.3.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+6 -11
View File
@@ -14,7 +14,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-parent</artifactId>
<packaging>pom</packaging>
<version>1.2.0</version>
<version>1.3.2</version>
<modules>
<module>easyplugin-bom</module>
@@ -75,11 +75,6 @@
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>carm-repo</id>
<name>Carm's Repo</name>
@@ -87,14 +82,14 @@
</repository>
<repository>
<id>EasySQL</id>
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
<url>https://maven.pkg.github.com/CarmJos/*</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
@@ -107,14 +102,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>