Skip to content

Commit

Permalink
Tpa命令支持多条,更新README
Browse files Browse the repository at this point in the history
  • Loading branch information
lRENyaaa committed Dec 31, 2023
1 parent 754112e commit f18f560
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## TpaForm Tpa Form支持
为Tpa相关命令添加Form菜单,基于命令监听实现
## 使用方式
指令/tform打开传送菜单,选择玩家后传送
基岩版玩家在接收到传送请求后自动弹出菜单
## 兼容的插件
绝大部分非跨服, 以指令为基础的Tpa均可通过调整配置文件兼容
目前已经测试的插件有:
* [EssentialX](https://essentialsx.net/)
* [CMI](https://www.spigotmc.org/resources/3742/)
* [Sunlight](https://www.spigotmc.org/resources/67733/)
* [HuskHomes](https://github.com/WiIIiam278/HuskHomes) (仅单端)
* [TPAPro](https://www.mcbbs.net/thread-904737-1-1.html) (需要从 [此处](https://raw.githubusercontent.com/RenYuan-MC/TpaForm/master/extensions/TpaForm-TpaProSupport.jar) 下载扩展以兼容其黑名单功能)
## 前置
* Floodgate (2.2.0版本以上) - 用于基岩版菜单
Binary file added extensions/TpaForm-TpaProSupport.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ltd.rymc</groupId>
<artifactId>TpaForm</artifactId>
<version>2.0.1</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<name>TpaForm</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ltd/rymc/form/tpa/configs/LangConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface LangConfig {
@ConfComments("\n# 传送选择菜单")
@AnnotationBasedSorter.Order(40)
String selectPlayers();

@ConfDefault.DefaultString("玩家列表")
@ConfKey("player-list")
@AnnotationBasedSorter.Order(50)
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/ltd/rymc/form/tpa/configs/TpaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import space.arim.dazzleconf.annote.ConfKey;
import space.arim.dazzleconf.sorter.AnnotationBasedSorter;

import java.util.List;

@SuppressWarnings("unused")
@ConfHeader("# 配置文件 TpaForm Config ver 2.0.0 by RENaa_FD")
public interface TpaConfig {
Expand Down Expand Up @@ -34,21 +36,21 @@ public interface TpaConfig {
@AnnotationBasedSorter.Order(20)
boolean enableTpaHere();

@ConfDefault.DefaultString("tpa")
@ConfKey("tpa-command")
@ConfDefault.DefaultStrings({"tpa"})
@ConfKey("tpa-commands")
@ConfComments({
"",
"# tpa相关的命令",
"# 接受和拒绝传送的命令支持使用%s指定玩家名",
"# 示例: tpaccept %s"
})
@AnnotationBasedSorter.Order(30)
String tpaCommand();
List<String> tpaCommands();

@ConfDefault.DefaultString("tpahere")
@ConfKey("tpa-here-command")
@ConfDefault.DefaultStrings({"tpahere"})
@ConfKey("tpa-here-commands")
@AnnotationBasedSorter.Order(40)
String tpaHereCommand();
List<String> tpaHereCommands();

@ConfDefault.DefaultString("tpaccept")
@ConfKey("tpa-accept-command")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ltd/rymc/form/tpa/forms/TpaSendForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private String[] getPlayerNameList(){
@Override
public void onValidResult(CustomForm form, CustomFormResponse response) {

String command = (response.asToggle(2) ? TpaForm.config().tpaHereCommand() : TpaForm.config().tpaCommand()) + " ";
String command = (response.asToggle(2) ? TpaForm.config().tpaHereCommands().get(0) : TpaForm.config().tpaCommands().get(0)) + " ";
String input = response.asInput(1);

String playerName;
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/ltd/rymc/form/tpa/listener/TpaCommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

import java.util.List;
import java.util.Locale;

public class TpaCommandListener implements Listener {
Expand All @@ -21,25 +22,26 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
String message = event.getMessage().trim().toLowerCase(Locale.ROOT).substring(1);

// check tpa
String command = TpaForm.config().tpaCommand();
String playerName = processCommand(message, command);
List<String> commands = TpaForm.config().tpaCommands();
TpaPlayer tpaPlayer = processCommand(message, commands);
TpaMode mode = TpaMode.TPA;

// check tpa here
if (TpaForm.config().enableTpaHere() && (playerName == null || playerName.contains(" "))) {
command = TpaForm.config().tpaHereCommand();
playerName = processCommand(message, command);
if (TpaForm.config().enableTpaHere() && (tpaPlayer == null || tpaPlayer.checkPlayerName())) {
commands = TpaForm.config().tpaHereCommands();
tpaPlayer = processCommand(message, commands);
mode = TpaMode.TPAHERE;
}

// check player name
if (playerName == null || playerName.contains(" ") || playerName.isEmpty()) return;
if (event.getPlayer().getName().equalsIgnoreCase(playerName)) return;
if (tpaPlayer == null || tpaPlayer.checkPlayerName()) return;
if (event.getPlayer().getName().equalsIgnoreCase(tpaPlayer.playerName)) return;
String playerName = tpaPlayer.playerName;

// completion
if (TpaForm.config().completion()) {
playerName = PlayerUtils.completionPlayer(playerName);
event.setMessage("/" + command + " " + playerName);
event.setMessage("/" + tpaPlayer.command + " " + playerName);
}

// get player
Expand All @@ -52,8 +54,26 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){



private String processCommand(String message,String command){
if (!message.startsWith(command.toLowerCase(Locale.ROOT))) return null;
return message.substring(command.length()).trim();
private TpaPlayer processCommand(String message, List<String> commands){
for (String command : commands){
if (!message.startsWith(command.toLowerCase(Locale.ROOT))) continue;
return new TpaPlayer(message.substring(command.length()).trim(), command);
}
return null;
}

private static class TpaPlayer {

private final String playerName;
private final String command;

private TpaPlayer(String playerName, String command){
this.playerName = playerName;
this.command = command;
}

private boolean checkPlayerName(){
return playerName.contains(" ") || playerName.isEmpty();
}
}
}
}

0 comments on commit f18f560

Please sign in to comment.