Skip to content

Commit

Permalink
支持设置白名单超时时间, 添加 PAPI 的初步支持
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed May 4, 2024
1 parent 25252d8 commit aa2a7f7
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 6 deletions.
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ApliNi</groupId>
<artifactId>IpacWhitelist</artifactId>
<version>4.1.1-rc2</version>
<version>4.1.1-rc4</version>
<packaging>jar</packaging>

<name>IpacWhitelist</name>
Expand Down Expand Up @@ -75,6 +75,10 @@
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/main/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -91,6 +95,12 @@
<scope>compile</scope>
</dependency>
<!-- 以下是我们自己添加的依赖 -->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/aplini/ipacwhitelist/IpacWhitelist.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package aplini.ipacwhitelist;

import aplini.ipacwhitelist.api.PlaceholderAPI;
import aplini.ipacwhitelist.hook.authMe;
import aplini.ipacwhitelist.listener.commandHandler;
import aplini.ipacwhitelist.listener.onPlayerLogin;
Expand Down Expand Up @@ -45,6 +46,9 @@ public void onEnable(){
if(config.getBoolean("hook.AuthMe", true)){
getServer().getPluginManager().registerEvents(new authMe(), plugin);
}
if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
new PlaceholderAPI().register();
}

// 注册指令
Objects.requireNonNull(getCommand("wl")).setExecutor(new commandHandler());
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/aplini/ipacwhitelist/api/PlaceholderAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package aplini.ipacwhitelist.api;

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 static aplini.ipacwhitelist.IpacWhitelist.config;

public class PlaceholderAPI extends PlaceholderExpansion {

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

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

@Override
public String getVersion() {
return "0.0.1";
}

@Override
public boolean persist() {
return true;
}

@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;
}

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);
}

return null;
}
}
1 change: 1 addition & 0 deletions src/main/java/aplini/ipacwhitelist/listener/cmd/add.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static void cmd(CommandSender sender, String[] args){
}
// 非 NOT 类型
if(li.isExist()){
li.save(); // 更新时间记录
sender.sendMessage(msg(config.getString("command.add.isExist", ""), li.uuid, li.name));
return;
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/aplini/ipacwhitelist/listener/onPlayerLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import static aplini.ipacwhitelist.hook.geyser.isGeyserPlayer;
import static aplini.ipacwhitelist.utils.netReq.isPremiumPlayer;
import static aplini.ipacwhitelist.utils.sql.getPlayerData;
import static aplini.ipacwhitelist.utils.util.SEL;
import static aplini.ipacwhitelist.utils.util.msg;
import static aplini.ipacwhitelist.utils.util.*;
import static org.bukkit.event.player.PlayerLoginEvent.Result.KICK_OTHER;

public class onPlayerLogin implements Listener {
Expand Down Expand Up @@ -279,16 +278,23 @@ else if(onOtherPlayer != Type.NOT){

// 白名单
case WHITE -> {
// 白名单超时
if(getTime() - pd.time > config.getLong("whitelist.WHITE.timeOut", 18394560)){
event.disallow(KICK_OTHER, config.getString("whitelist.WHITE.timeOutMsg", ""));
return;
}
event.allow();
}

default -> {
plugin.getLogger().warning("出现未知的错误: 不存在有效数据的玩家登录服务器: "+ player.getUniqueId());
event.disallow(KICK_OTHER, config.getString("message.playerLoginErr", ""));
return;
}
}

// 保存玩家数据
// 以上代码通过 return 来绕过这里的保存操作, 只有成功加入游戏才需要保存
pd.save();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/aplini/ipacwhitelist/utils/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PlayerData {
public Type ban = Type.NOT;
public String uuid = null;
public String name = null;
public long time = 0;
public long time = 0; // 秒级时间戳
public PlayerConfig config = new PlayerConfig();

// 保存数据时是否更新时间
Expand Down
18 changes: 17 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ whitelist:

# 白名单中的玩家
WHITE:

# 距离上一次上线超过此时间就踢出, 如果需要取消可以修改为较大的数值
timeOut: 18394560 # 7个月
timeOutMsg: '§6IpacEL §f> §a白名单已超时, 请联系管理员恢复'

onPlayerLoginEvent: [ ] # 玩家登录服务器

onPlayerJoinEvent: # 玩家加入服务器
Expand Down Expand Up @@ -199,7 +204,7 @@ command:
add:
title: '§6IpacEL §f> §a添加到白名单[§b%var%§a]:'
isBan: ' - §a%playerName%§f[§7%playerUUID%§f] §b已在黑名单中, 不可操作'
isExist: ' - §a%playerName%§f[§7%playerUUID%§f] §b已在白名单中'
isExist: ' - §a%playerName%§f[§7%playerUUID%§f] §b已在白名单中, 已更新时间记录'
isVisit: ' - §a%playerName%§f[§7%playerUUID%§f] §a已从参观账户中重置'
finish: ' - §a%playerName%§f[§7%playerUUID%§f] §a已完成'

Expand Down Expand Up @@ -308,6 +313,17 @@ command:
TIME: 5


# API 相关配置
api:
PlaceholderAPI:
iwl_player_type: {}
iwl_player_type_name:
NOT: '不存在'
VISIT: '参观账户'
WHITE: '白名单'
VISIT_CONVERT: '白名单 (正在转换)'
BAN: '已封禁'

# 其他消息
message:
noEnable: '§6IpacEL §f> §b功能未启用'
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: IpacWhitelist
authors: [ ApliNi ]
version: '${project.version}'
main: aplini.ipacwhitelist.IpacWhitelist
api-version: 1.19

softdepend:
- AuthMe
- Geyser-Spigot
- PlaceholderAPI

commands:
wl:
description: 白名单指令
usage: /<command>
aliases: [ipacwhitelist]
aliases: [ ipacwhitelist ]

permissions:

Expand Down

0 comments on commit aa2a7f7

Please sign in to comment.