diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessaging.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessaging.java index 583ebab..d5d5a70 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessaging.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/AziPluginMessaging.java @@ -1,5 +1,6 @@ package net.azisaba.azipluginmessaging.api; +import net.azisaba.azipluginmessaging.api.entity.PlayerAdapter; import net.azisaba.azipluginmessaging.api.server.PacketSender; import org.jetbrains.annotations.NotNull; @@ -29,6 +30,19 @@ public interface AziPluginMessaging { @NotNull Server getServer(); + /** + * Returns the player adapter for class. + *

Generally, class should be one of these (depending on the environment): + *

+ * @param clazz the platform dependent player class + * @return the player adapter + * @param the player class + */ + PlayerAdapter getPlayerAdapter(@NotNull Class clazz); + interface Proxy { /** * Returns the packet sender instance for provided server. diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/entity/PlayerAdapter.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/entity/PlayerAdapter.java new file mode 100644 index 0000000..4a2a2cd --- /dev/null +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/entity/PlayerAdapter.java @@ -0,0 +1,13 @@ +package net.azisaba.azipluginmessaging.api.entity; + +import org.jetbrains.annotations.NotNull; + +public interface PlayerAdapter { + /** + * Returns the player object from platform dependent player object. + * @param player the platform dependent player + * @return the player object + */ + @NotNull + Player get(@NotNull T player); +} diff --git a/build.gradle.kts b/build.gradle.kts index c2e9e4f..a28fa63 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "net.azisaba.azipluginmessaging" -version = "1.0.0" +version = "1.1.0" repositories { mavenCentral() diff --git a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/AziPluginMessagingSpigot.java b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/AziPluginMessagingSpigot.java index 2a043a7..5107dec 100644 --- a/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/AziPluginMessagingSpigot.java +++ b/spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/AziPluginMessagingSpigot.java @@ -2,9 +2,11 @@ import net.azisaba.azipluginmessaging.api.AziPluginMessaging; import net.azisaba.azipluginmessaging.api.Logger; +import net.azisaba.azipluginmessaging.api.entity.PlayerAdapter; import net.azisaba.azipluginmessaging.api.server.PacketSender; import net.azisaba.azipluginmessaging.spigot.entity.PlayerImpl; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -33,6 +35,13 @@ public AziPluginMessagingSpigot(@NotNull SpigotPlugin plugin) { return server; } + @SuppressWarnings("unchecked") + @Override + public PlayerAdapter getPlayerAdapter(@NotNull Class clazz) { + if (!Player.class.equals(clazz)) throw new IllegalArgumentException("This environment does not support " + clazz.getTypeName()); + return (PlayerAdapter) (PlayerAdapter) PlayerImpl::new; + } + public static class ServerImpl implements Server { @Override public @NotNull PacketSender getPacketSender() { diff --git a/velocity/src/main/java/net/azisaba/azipluginmessaging/velocity/AziPluginMessagingVelocity.java b/velocity/src/main/java/net/azisaba/azipluginmessaging/velocity/AziPluginMessagingVelocity.java index 2c058c5..2d717fa 100644 --- a/velocity/src/main/java/net/azisaba/azipluginmessaging/velocity/AziPluginMessagingVelocity.java +++ b/velocity/src/main/java/net/azisaba/azipluginmessaging/velocity/AziPluginMessagingVelocity.java @@ -1,11 +1,14 @@ package net.azisaba.azipluginmessaging.velocity; +import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import net.azisaba.azipluginmessaging.api.AziPluginMessaging; import net.azisaba.azipluginmessaging.api.Logger; +import net.azisaba.azipluginmessaging.api.entity.PlayerAdapter; import net.azisaba.azipluginmessaging.api.protocol.Protocol; import net.azisaba.azipluginmessaging.api.server.PacketSender; +import net.azisaba.azipluginmessaging.velocity.entity.PlayerImpl; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -36,6 +39,13 @@ public AziPluginMessagingVelocity(@NotNull ProxyServer server, @NotNull org.slf4 return new Server() {}; } + @SuppressWarnings("unchecked") + @Override + public PlayerAdapter getPlayerAdapter(@NotNull Class clazz) { + if (!Player.class.equals(clazz)) throw new IllegalArgumentException("This environment does not support " + clazz.getTypeName()); + return (PlayerAdapter) (PlayerAdapter) PlayerImpl::new; + } + public class ProxyImpl implements Proxy { @Override public @NotNull Optional getPacketSenderForServer(@NotNull String serverName) {