Skip to content

Commit

Permalink
修复 papi 功能, 添加新的使用方法
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed May 5, 2024
1 parent 9bcdd72 commit faffca7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ v4 版本改动特别大, 建议不要从旧配置中复制内容到新配置,
## API 和扩展功能

#### PlaceholderAPI 占位符
- `iwl_player_type_name` - 显示当前玩家类型的显示名称, 名称可配置
- `iwl_player_type` - 显示当前玩家类型的内部名称
- `%iwl_player_type%` - 显示当前玩家类型的内部名称
- `%iwl_player_type(playerName|playerUUID)%` - 显示指定玩家类型的内部名称
- `%iwl_player_type_name%` - 显示当前玩家类型的显示名称, 名称可配置
- `%iwl_player_type_name(playerName|playerUUID)%` - 显示指定玩家类型的显示名称, 名称可配置

---

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/aplini/ipacwhitelist/IpacWhitelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void onEnable(){
getServer().getPluginManager().registerEvents(new authMe(), plugin);
}
if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
new PlaceholderAPI().register();
new PlaceholderAPI(plugin).register();
}

// 注册指令
Expand Down
45 changes: 38 additions & 7 deletions src/main/java/aplini/ipacwhitelist/api/PlaceholderAPI.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
package aplini.ipacwhitelist.api;

import aplini.ipacwhitelist.IpacWhitelist;
import aplini.ipacwhitelist.enums.Type;
import aplini.ipacwhitelist.utils.Inp;
import aplini.ipacwhitelist.utils.PlayerData;
import aplini.ipacwhitelist.utils.sql;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static aplini.ipacwhitelist.IpacWhitelist.config;

public class PlaceholderAPI extends PlaceholderExpansion {

private final IpacWhitelist plugin;

public PlaceholderAPI(IpacWhitelist plugin) {
this.plugin = plugin;
}

@Override
@NotNull
public String getAuthor() {
return "ApliNi";
}

@Override
@NotNull
public String getIdentifier() {
return "IpacWhitelist";
return "iwl";
}

@Override
@NotNull
public String getVersion() {
return "0.0.1";
}
Expand All @@ -30,17 +45,33 @@ public boolean persist() {
return true;
}

static Pattern pattern = Pattern.compile("^(.+)\\((.+)\\)$");

@Override
public String onRequest(OfflinePlayer player, @NotNull String params){

if(params.equalsIgnoreCase("iwl_player_type")){
PlayerData pd = sql.getPlayerData(player.getUniqueId().toString(), player.getName(), false);
return pd.type.name;
// 如果这是一个带参数的变量
Matcher matcher = pattern.matcher(params);
String cmd = null, playerInp = null;
if(matcher.find()){
cmd = matcher.group(1);
playerInp = matcher.group(2);
}

if(params.equalsIgnoreCase("iwl_player_type_name")){
PlayerData pd = sql.getPlayerData(player.getUniqueId().toString(), player.getName(), false);
return config.getString("api.PlaceholderAPI.iwl_player_type_name."+ pd.type.name, "未定义变量名 "+ pd.type.name);
cmd = (cmd == null)? params.toLowerCase() : cmd.toLowerCase();
playerInp = (playerInp == null)? player.getUniqueId().toString() : playerInp;

Inp inp = new Inp().fromInp(playerInp, false);

switch(cmd){
case "player_type" -> {
Type type = (inp.pd.ban == Type.BAN)? Type.BAN : inp.pd.type;
return type.name;
}
case "player_type_name" -> {
Type type = (inp.pd.ban == Type.BAN)? Type.BAN : inp.pd.type;
return config.getString("api.PlaceholderAPI.iwl_player_type_name." + type.name, "未定义变量名 " + type.name);
}
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ whitelist:
ipBlacklist: [ ]
# - '^/192\.168\.100\..+$'
# - '^/fe80::1234:.+$'
ipBlacklistMsg: '§6IpacEL §f> §b您的 IP 已被列入黑名单: §a%playerName%' # var: %ip%
ipBlacklistMsg: '§6IpacEL §f> §b您的 IP 已被列入黑名单' # var: %ip%

# 限定玩家只能通过以下地址连接服务器
addressConfig:
Expand Down

0 comments on commit faffca7

Please sign in to comment.