Skip to content

Commit

Permalink
[构建跳过] 重构
Browse files Browse the repository at this point in the history
  • Loading branch information
lRENyaaa committed Dec 30, 2023
1 parent 09ab599 commit a67ea0f
Show file tree
Hide file tree
Showing 23 changed files with 838 additions and 292 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: TpaForm 自动构建

on: [push, pull_request]

jobs:
build:

if: contains(github.event.head_commit.message, '[构建跳过]') == false
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Maven
run: mvn package --file pom.xml
- name: Archive artifacts
uses: actions/upload-artifact@v3
if: success()
with:
name: TpaForm
path: target/TpaForm.jar
- name: Automatic Releases
uses: marvinpinto/[email protected]
if: success()
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "dev"
prerelease: false
title: "TpaForm 自动构建版本"
files: |
target/TpaForm.jar
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Tpa
TPA命令BE Form支持
## TpaForm Tpa Form支持
为Tpa相关命令添加Form菜单,基于命令监听实现
## 前置
* Floodgate (2.2.0版本以上) - 用于基岩版菜单
47 changes: 36 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
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>ren.rymc</groupId>
<artifactId>tpa</artifactId>
<version>1.2.4</version>
<groupId>ltd.rymc</groupId>
<artifactId>TpaForm</artifactId>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>Tpa</name>
<name>TpaForm</name>

<description>Tpa Form菜单支持</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>https://rymc.ltd/</url>

<build>
<finalName>TpaForm</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -39,6 +42,16 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<pattern>space.arim.dazzleconf</pattern>
<shadedPattern>ltd.rymc.form.tpa.lib.dazzleconf</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>ltd.rymc.form.tpa.lib.acf</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
Expand All @@ -57,28 +70,40 @@
<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>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
</repository>
<repository>
<id>aikar-repo</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.floodgate</groupId>
<artifactId>api</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>space.arim.dazzleconf</groupId>
<artifactId>dazzleconf-ext-snakeyaml</artifactId>
<version>1.3.0-M2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
55 changes: 55 additions & 0 deletions src/main/java/ltd/rymc/form/tpa/TpaForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ltd.rymc.form.tpa;

import co.aikar.commands.PaperCommandManager;
import ltd.rymc.form.tpa.commands.TpaFormCommand;
import ltd.rymc.form.tpa.config.ConfigManager;
import ltd.rymc.form.tpa.configs.LangConfig;
import ltd.rymc.form.tpa.configs.TpaConfig;
import ltd.rymc.form.tpa.listener.TpaCommandListener;
import ltd.rymc.form.tpa.metrics.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class TpaForm extends JavaPlugin {

private static TpaForm instance;
private static ConfigManager<TpaConfig> tpaConfigManager;
private static ConfigManager<LangConfig> langConfigManager;
private static PaperCommandManager commandManager;

@Override
public void onEnable() {
instance = this;
tpaConfigManager = ConfigManager.create(TpaForm.getInstance().getDataFolder().toPath(),"config.yml", TpaConfig.class);
langConfigManager = ConfigManager.create(TpaForm.getInstance().getDataFolder().toPath(), "lang.yml", LangConfig.class);
reload();

commandManager = new PaperCommandManager(this);
commandManager.registerCommand(new TpaFormCommand());

Bukkit.getPluginManager().registerEvents(new TpaCommandListener(), this);

if (config().metrics()){
new Metrics(this, 16561);
}

}

public static void reload(){
tpaConfigManager.reloadConfig();
langConfigManager.reloadConfig();
}

public static TpaConfig config(){
return tpaConfigManager.getConfigData();
}

public static LangConfig lang(){
return langConfigManager.getConfigData();
}

public static TpaForm getInstance() {
return instance;
}

}
33 changes: 33 additions & 0 deletions src/main/java/ltd/rymc/form/tpa/commands/TpaFormCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ltd.rymc.form.tpa.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand;
import ltd.rymc.form.tpa.TpaForm;
import ltd.rymc.form.tpa.forms.TpaSendForm;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

@SuppressWarnings("unused")
@CommandAlias("tpaui|tform")
@Description("TpaForm Form菜单")
public class TpaFormCommand extends BaseCommand {

@Default
public void main(CommandSender sender){
if (!(sender instanceof Player)) return;

Player player = ((Player) sender);
new TpaSendForm(player,null).send();
}

@Subcommand("reload")
@CommandPermission("tpaform.reload")
public void reload(CommandSender sender){
TpaForm.reload();
sender.sendMessage((sender instanceof Player ? TpaForm.lang().prefix() : "") + TpaForm.lang().reload());
}
}
67 changes: 67 additions & 0 deletions src/main/java/ltd/rymc/form/tpa/config/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ltd.rymc.form.tpa.config;

import ltd.rymc.form.tpa.TpaForm;
import space.arim.dazzleconf.ConfigurationFactory;
import space.arim.dazzleconf.ConfigurationOptions;
import space.arim.dazzleconf.error.ConfigFormatSyntaxException;
import space.arim.dazzleconf.error.InvalidConfigException;
import space.arim.dazzleconf.ext.snakeyaml.CommentMode;
import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlConfigurationFactory;
import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlOptions;
import space.arim.dazzleconf.helper.ConfigurationHelper;
import space.arim.dazzleconf.sorter.AnnotationBasedSorter;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;

public final class ConfigManager<C> {

private final ConfigurationHelper<C> configHelper;
private volatile C configData;

private ConfigManager(ConfigurationHelper<C> configHelper) {
this.configHelper = configHelper;
}

public static <C> ConfigManager<C> create(Path configFolder, String fileName, Class<C> configClass) {
// SnakeYaml example
SnakeYamlOptions yamlOptions = new SnakeYamlOptions.Builder()
.commentMode(CommentMode.alternativeWriter("%s"))
.build();
ConfigurationFactory<C> configFactory = SnakeYamlConfigurationFactory.create(
configClass,
new ConfigurationOptions.Builder().sorter(new AnnotationBasedSorter()).build(),
yamlOptions);
return new ConfigManager<>(new ConfigurationHelper<>(configFolder, fileName, configFactory)) ;
}

public void reloadConfig() {
try {
configData = configHelper.reloadConfigData();
} catch (IOException ex) {
throw new UncheckedIOException(ex);

} catch (ConfigFormatSyntaxException ex) {
configData = configHelper.getFactory().loadDefaults();
TpaForm.getInstance().getLogger().severe("The yaml syntax in your configuration is invalid. "
+ "Check your YAML syntax with a tool such as https://yaml-online-parser.appspot.com/");
ex.printStackTrace();

} catch (InvalidConfigException ex) {
configData = configHelper.getFactory().loadDefaults();
TpaForm.getInstance().getLogger().severe("One of the values in your configuration is not valid. "
+ "Check to make sure you have specified the right data types.");
ex.printStackTrace();
}
}

public C getConfigData() {
C configData = this.configData;
if (configData == null) {
throw new IllegalStateException("Configuration has not been loaded yet");
}
return configData;
}

}
74 changes: 74 additions & 0 deletions src/main/java/ltd/rymc/form/tpa/configs/LangConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package ltd.rymc.form.tpa.configs;

import space.arim.dazzleconf.annote.ConfComments;
import space.arim.dazzleconf.annote.ConfDefault;
import space.arim.dazzleconf.annote.ConfHeader;
import space.arim.dazzleconf.annote.ConfKey;
import space.arim.dazzleconf.sorter.AnnotationBasedSorter;

@SuppressWarnings("unused")
@ConfHeader("# 语言文件 TpaForm Lang zh_cn ver 2.0.0 by RENaa_FD")
public interface LangConfig {
@ConfDefault.DefaultString("§f[§6服务器§f] ")
@ConfKey("prefix")
@ConfComments("\n# 重载插件部分")
@AnnotationBasedSorter.Order(10)
String prefix();

@ConfDefault.DefaultString("插件已重载!")
@ConfKey("reload")
@AnnotationBasedSorter.Order(20)
String reload();

@ConfDefault.DefaultString("传送菜单")
@ConfKey("title")
@ConfComments("\n# 菜单标题")
@AnnotationBasedSorter.Order(30)
String title();

@ConfDefault.DefaultString("请选择玩家")
@ConfKey("select-players")
@ConfComments("\n# 传送选择菜单")
@AnnotationBasedSorter.Order(40)
String selectPlayers();
@ConfDefault.DefaultString("玩家列表")
@ConfKey("player-list")
@AnnotationBasedSorter.Order(50)
String playerList();

@ConfDefault.DefaultString("如果上方找起来过于麻烦可以使用这个输入框")
@ConfKey("input-tips")
@AnnotationBasedSorter.Order(60)
String inputTips();

@ConfDefault.DefaultString("无需输入完整玩家名")
@ConfKey("input-tips1")
@AnnotationBasedSorter.Order(70)
String inputTips1();

@ConfDefault.DefaultString("模式(开为传送到你这,关为传送到你选择的玩家)")
@ConfKey("tpa-mode")
@AnnotationBasedSorter.Order(80)
String tpaMode();

@ConfDefault.DefaultString("%s 想要传送到你这")
@ConfKey("tpa")
@ConfComments("\n# 传送接受菜单")
@AnnotationBasedSorter.Order(90)
String tpa();

@ConfDefault.DefaultString("%s 想要让你传送到他那")
@ConfKey("tpa-here")
@AnnotationBasedSorter.Order(100)
String tpaHere();

@ConfDefault.DefaultString("同意传送")
@ConfKey("accept")
@AnnotationBasedSorter.Order(110)
String accept();

@ConfDefault.DefaultString("拒绝传送")
@ConfKey("deny")
@AnnotationBasedSorter.Order(120)
String deny();
}
Loading

0 comments on commit a67ea0f

Please sign in to comment.