可选依赖至AuthMe,实现在线玩家列表
This commit is contained in:
17
pom.xml
17
pom.xml
@@ -131,9 +131,20 @@
|
|||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>codemc-repo</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>fr.xephi</groupId>
|
||||||
|
<artifactId>authme</artifactId>
|
||||||
|
<version>5.6.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
@@ -152,5 +163,11 @@
|
|||||||
<artifactId>jooq</artifactId>
|
<artifactId>jooq</artifactId>
|
||||||
<version>3.19.16</version>
|
<version>3.19.16</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package ling.coordinateRecorder.Commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// zb命令处理器
|
||||||
|
public class ZbCommand implements CommandExecutor, TabCompleter {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command,
|
||||||
|
@NotNull String s, @NotNull String[] strings) {
|
||||||
|
assert s.equals("zb");
|
||||||
|
if (!(commandSender instanceof Player)) {
|
||||||
|
System.out.println("该命令只能由玩家执行");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package ling.coordinateRecorder;
|
package ling.coordinateRecorder;
|
||||||
|
|
||||||
|
import ling.coordinateRecorder.Listener.PlayerAuthMeLoginEventListener;
|
||||||
|
import ling.coordinateRecorder.Listener.PlayerEventListener;
|
||||||
|
import ling.coordinateRecorder.Listener.PlayerLoginEventListener;
|
||||||
import ling.coordinateRecorder.data.Database;
|
import ling.coordinateRecorder.data.Database;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -9,18 +14,32 @@ public final class CoordinateRecorder extends JavaPlugin {
|
|||||||
|
|
||||||
private static CoordinateRecorder current;
|
private static CoordinateRecorder current;
|
||||||
private static Database database;
|
private static Database database;
|
||||||
|
private static Plugin authMePlugin;
|
||||||
|
|
||||||
private static void start() throws SQLException {
|
private static void start() throws SQLException {
|
||||||
database.installPlugin();
|
database.installPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadListener() {
|
||||||
|
Bukkit.getPluginManager().registerEvents(new PlayerEventListener(), this);
|
||||||
|
if (authMePlugin != null && authMePlugin.isEnabled()) {
|
||||||
|
getLogger().info("找到AuthMe插件,将使用AuthMe兼容接口");
|
||||||
|
Bukkit.getPluginManager().registerEvents(new PlayerAuthMeLoginEventListener(), this);
|
||||||
|
} else {
|
||||||
|
getLogger().info("没有找到AuthMe插件,使用原版接口");
|
||||||
|
Bukkit.getPluginManager().registerEvents(new PlayerLoginEventListener(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
current = this;
|
current = this;
|
||||||
|
authMePlugin = Bukkit.getPluginManager().getPlugin("AuthMe");
|
||||||
try {
|
try {
|
||||||
database = new Database(this);
|
database = new Database(this);
|
||||||
start();
|
start();
|
||||||
|
loadListener();
|
||||||
getLogger().info("加载完毕");
|
getLogger().info("加载完毕");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException("插件初始化失败", e);
|
throw new RuntimeException("插件初始化失败", e);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package ling.coordinateRecorder.Listener;
|
||||||
|
|
||||||
|
import fr.xephi.authme.events.LoginEvent;
|
||||||
|
import fr.xephi.authme.events.LogoutEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/// 玩家通过AuthMe插件登录验证
|
||||||
|
public class PlayerAuthMeLoginEventListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void playerLogin(LoginEvent event) {
|
||||||
|
PlayerMap.getCurrent().playerLogin(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerLogout(LogoutEvent event) {
|
||||||
|
PlayerMap.getCurrent().playerQuit(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package ling.coordinateRecorder.Listener;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
/// 玩家事件监听器
|
||||||
|
public class PlayerEventListener implements Listener {
|
||||||
|
|
||||||
|
/// 玩家登出
|
||||||
|
@EventHandler
|
||||||
|
public void playerQuit(PlayerQuitEvent event) {
|
||||||
|
PlayerMap.getCurrent().playerQuit(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 玩家移动
|
||||||
|
@EventHandler
|
||||||
|
public void playerMove(PlayerMoveEvent event) {
|
||||||
|
PlayerMap.getCurrent().playerMove(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package ling.coordinateRecorder.Listener;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
/// 玩家连入服务器
|
||||||
|
public class PlayerLoginEventListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerLogin(PlayerJoinEvent event) {
|
||||||
|
PlayerMap.getCurrent().playerLogin(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package ling.coordinateRecorder.Listener;
|
||||||
|
|
||||||
|
import ling.coordinateRecorder.CoordinateRecorder;
|
||||||
|
import ling.coordinateRecorder.data.PlayerData;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/// 在线玩家集合
|
||||||
|
public class PlayerMap {
|
||||||
|
protected HashMap<UUID, PlayerData> playerList = new HashMap<>();
|
||||||
|
protected static final CoordinateRecorder plugin = CoordinateRecorder.getCurrent();
|
||||||
|
protected static final PlayerMap current = new PlayerMap();
|
||||||
|
|
||||||
|
private PlayerMap() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerMap getCurrent() {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerData getPlayerData(@NotNull Player player) {
|
||||||
|
return getPlayerData(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerData getPlayerData(UUID uuid) {
|
||||||
|
return playerList.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 玩家登录
|
||||||
|
protected void playerLogin(Player player) {
|
||||||
|
if (!playerList.containsKey(player.getUniqueId())) {
|
||||||
|
plugin.getLogger().info("玩家[" + player.getName() + "]登录服务器,已添加到管理列表");
|
||||||
|
playerList.put(player.getUniqueId(), new PlayerData(player));
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().warning("玩家[" + player.getName() + "]已经在管理列表中");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 玩家退出
|
||||||
|
protected void playerQuit(Player player) {
|
||||||
|
if (playerList.containsKey(player.getUniqueId())) {
|
||||||
|
playerList.remove(player.getUniqueId());
|
||||||
|
plugin.getLogger().info("玩家[" + player.getName() + "]退出服务器,停止管理");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void playerMove(Player player) {
|
||||||
|
var data = playerList.get(player.getUniqueId());
|
||||||
|
if (data != null)
|
||||||
|
data.updateLocal();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/main/java/ling/coordinateRecorder/data/PlayerData.java
Normal file
17
src/main/java/ling/coordinateRecorder/data/PlayerData.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package ling.coordinateRecorder.data;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/// 玩家的附加信息
|
||||||
|
public class PlayerData {
|
||||||
|
protected final Player player;
|
||||||
|
|
||||||
|
public PlayerData(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 玩家位置信息发生改变
|
||||||
|
public void updateLocal() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,3 +2,9 @@ name: CoordinateRecorder
|
|||||||
version: '1.0'
|
version: '1.0'
|
||||||
main: ling.coordinateRecorder.CoordinateRecorder
|
main: ling.coordinateRecorder.CoordinateRecorder
|
||||||
api-version: '1.21'
|
api-version: '1.21'
|
||||||
|
softdepend:
|
||||||
|
- AuthMe
|
||||||
|
commands:
|
||||||
|
zb:
|
||||||
|
usage: "/zb <选项> <参数>"
|
||||||
|
description: "使用坐标管理器来记录坐标位置"
|
||||||
Reference in New Issue
Block a user