feat: 添加了连接已启用的事件
This commit is contained in:
@@ -4,8 +4,8 @@ import cn.hamster3.mc.plugin.ball.bukkit.HamsterBallPlugin;
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.listener.BallBukkitListener;
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.config.BallConfig;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerType;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,10 +31,10 @@ public class BallBukkitAPI extends BallAPI {
|
||||
|
||||
String host = pluginConfig.getString("server-info.name.host", Bukkit.getIp());
|
||||
BallConfig config = new BallConfig(
|
||||
new ServerInfo(
|
||||
new BallServerInfo(
|
||||
pluginConfig.getString("server-info.id"),
|
||||
pluginConfig.getString("server-info.name"),
|
||||
ServerType.GAME,
|
||||
BallServerType.GAME,
|
||||
host.isEmpty() ? "127.0.0.1" : host,
|
||||
pluginConfig.getInt("server-info.name.port", Bukkit.getPort())
|
||||
),
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.bukkit.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceBlockPos;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallBlockPos;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BukkitBlockPos extends ServiceBlockPos {
|
||||
public class BukkitBlockPos extends BallBlockPos {
|
||||
public BukkitBlockPos(@NotNull String serverID, @NotNull String worldName, int x, int y, int z) {
|
||||
super(serverID, worldName, x, y, z);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class BukkitBlockPos extends ServiceBlockPos {
|
||||
);
|
||||
}
|
||||
|
||||
public BukkitBlockPos(@NotNull ServiceBlockPos location) {
|
||||
public BukkitBlockPos(@NotNull BallBlockPos location) {
|
||||
super(
|
||||
BallAPI.getInstance().getLocalServerId(),
|
||||
location.getWorldName(),
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.bukkit.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallLocation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BukkitLocation extends ServiceLocation {
|
||||
public class BukkitLocation extends BallLocation {
|
||||
public BukkitLocation(@NotNull String serverID, @NotNull String worldName, double x, double y, double z) {
|
||||
super(serverID, worldName, x, y, z, 0, 0);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class BukkitLocation extends ServiceLocation {
|
||||
);
|
||||
}
|
||||
|
||||
public BukkitLocation(@NotNull ServiceLocation location) {
|
||||
public BukkitLocation(@NotNull BallLocation location) {
|
||||
super(
|
||||
location.getServerID(),
|
||||
location.getWorldName(),
|
||||
|
@@ -2,13 +2,15 @@ package cn.hamster3.mc.plugin.ball.bukkit.listener;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.data.BukkitLocation;
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerType;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallLocation;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.operate.DispatchConsoleCommandEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.operate.DispatchPlayerCommandEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.operate.SendPlayerToLocationEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.operate.SendPlayerToPlayerEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -28,56 +30,7 @@ public class BallBukkitListener extends BallListener implements Listener {
|
||||
|
||||
private final HashMap<UUID, Location> playerToLocation = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onDispatchConsoleCommand(@NotNull DispatchConsoleCommandEvent event) {
|
||||
if (event.getType() != null && event.getType() != ServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
if (event.getServerID() != null && !BallAPI.getInstance().isLocalServer(event.getServerID())) {
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDispatchPlayerCommand(@NotNull DispatchPlayerCommandEvent event) {
|
||||
if (event.getType() != null && event.getType() != ServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
if (event.getUuid() != null) {
|
||||
Player player = Bukkit.getPlayer(event.getUuid());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(player, event.getCommand());
|
||||
return;
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Bukkit.dispatchCommand(player, event.getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendPlayerToLocation(@NotNull SendPlayerToLocationEvent event) {
|
||||
ServiceLocation location = event.getLocation();
|
||||
if (!BallAPI.getInstance().isLocalServer(location.getServerID())) {
|
||||
return;
|
||||
}
|
||||
for (UUID uuid : event.getSendPlayerUUID()) {
|
||||
playerToLocation.put(uuid, new BukkitLocation(location).toBukkitLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendPlayerToPlayer(@NotNull SendPlayerToPlayerEvent event) {
|
||||
Player player = Bukkit.getPlayer(event.getToPlayerUUID());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
for (UUID uuid : event.getSendPlayerUUID()) {
|
||||
playerToLocation.put(uuid, location);
|
||||
}
|
||||
private BallBukkitListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +38,63 @@ public class BallBukkitListener extends BallListener implements Listener {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
||||
switch (info.getAction()) {
|
||||
case DispatchConsoleCommandEvent.ACTION: {
|
||||
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
if (event.getServerID() != null && !BallAPI.getInstance().isLocalServer(event.getServerID())) {
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getCommand());
|
||||
break;
|
||||
}
|
||||
case DispatchPlayerCommandEvent.ACTION: {
|
||||
DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
|
||||
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
if (event.getUuid() != null) {
|
||||
Player player = Bukkit.getPlayer(event.getUuid());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(player, event.getCommand());
|
||||
return;
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Bukkit.dispatchCommand(player, event.getCommand());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SendPlayerToLocationEvent.ACTION: {
|
||||
SendPlayerToLocationEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
|
||||
BallLocation location = event.getLocation();
|
||||
if (BallAPI.getInstance().isLocalServer(location.getServerID())) {
|
||||
for (UUID uuid : event.getSendPlayerUUID()) {
|
||||
playerToLocation.put(uuid, new BukkitLocation(location).toBukkitLocation());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SendPlayerToPlayerEvent.ACTION: {
|
||||
SendPlayerToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToPlayerEvent.class);
|
||||
Player player = Bukkit.getPlayer(event.getToPlayerUUID());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
for (UUID uuid : event.getSendPlayerUUID()) {
|
||||
playerToLocation.put(uuid, location);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
Reference in New Issue
Block a user