new module pandalib-paper-players
This commit is contained in:
parent
aff229164c
commit
37a267eae5
@ -19,6 +19,11 @@
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-players-standalone</artifactId>
|
||||
|
@ -13,6 +13,7 @@ import net.md_5.bungee.api.SkinConfiguration;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer.ChatMode;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer.MainHand;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.packet.ClientSettings;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
@ -20,9 +21,39 @@ import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import fr.pandacube.lib.chat.Chat;
|
||||
import fr.pandacube.lib.players.standalone.StandaloneOnlinePlayer;
|
||||
import fr.pandacube.lib.reflect.Reflect;
|
||||
import fr.pandacube.lib.util.MinecraftVersion;
|
||||
|
||||
public interface BungeeOnlinePlayer extends BungeeOffPlayer, StandaloneOnlinePlayer {
|
||||
|
||||
/*
|
||||
* General data and state
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
default String getName() {
|
||||
return getBungeeProxiedPlayer().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
default String getServerName() {
|
||||
if (getServer() == null) return null;
|
||||
return getServer().getInfo().getName();
|
||||
}
|
||||
|
||||
default Server getServer() {
|
||||
return getBungeeProxiedPlayer().getServer();
|
||||
}
|
||||
|
||||
default MinecraftVersion getMinecraftVersion() {
|
||||
return MinecraftVersion.getVersion(getBungeeProxiedPlayer().getPendingConnection().getVersion());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Related class instances
|
||||
*/
|
||||
|
||||
@Override
|
||||
ProxiedPlayer getBungeeProxiedPlayer();
|
||||
|
44
pandalib-paper-players/pom.xml
Normal file
44
pandalib-paper-players/pom.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>pandalib-parent</artifactId>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>pandalib-paper-players</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.lib</groupId>
|
||||
<artifactId>pandalib-players-standalone</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Paper -->
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>${paper.version}-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-mojangapi</artifactId>
|
||||
<version>${paper.version}-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,90 @@
|
||||
package fr.pandacub.lib.paper.players;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import fr.pandacube.lib.players.standalone.StandaloneOffPlayer;
|
||||
|
||||
public interface PaperOffPlayer extends StandaloneOffPlayer {
|
||||
|
||||
/*
|
||||
* General data and state
|
||||
*/
|
||||
|
||||
@Override
|
||||
default boolean isOnline() {
|
||||
return (getBukkitPlayer() != null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Related class instances
|
||||
*/
|
||||
|
||||
@Override
|
||||
PaperOnlinePlayer getOnlineInstance();
|
||||
|
||||
/**
|
||||
* @return l'instance Bukkit du joueur en ligne, ou null si il n'est pas en
|
||||
* ligne
|
||||
*/
|
||||
default Player getBukkitPlayer() {
|
||||
return Bukkit.getPlayer(getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bukkit’s {@link OfflinePlayer} instance for this player.
|
||||
* May represent a player that never joined the server before.
|
||||
* @return an instance of {@link OfflinePlayer} for this player.
|
||||
*/
|
||||
default OfflinePlayer getBukkitOfflinePlayer() {
|
||||
return Bukkit.getOfflinePlayer(getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Display name
|
||||
*/
|
||||
/**
|
||||
* Get the display name of the user, in legacy format.
|
||||
* @return the display name of the player.
|
||||
*
|
||||
* @implNote This default implementation gets the display name from bukkit (if the player is online).
|
||||
* If its different to the player name, it returns it. Otherwise, it tries to generate the team displayname with {@link #getTeamDisplayName()}.
|
||||
* If the player is not in a team, then the player name is used.
|
||||
*/
|
||||
@Override
|
||||
default String getDisplayName() {
|
||||
String name = getName();
|
||||
Player p = getBukkitPlayer();
|
||||
String bukkitDispName = p != null ? p.getDisplayName() : name;
|
||||
if (!name.equals(bukkitDispName))
|
||||
return bukkitDispName;
|
||||
String teamDispName = getTeamDisplayName();
|
||||
return teamDispName == null ? name : teamDispName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the the name of the player with the prefix, suffix and color of the team the player is in.
|
||||
* @return The legacy formated player display name, if he is in a {@link Team}, or null otherwise.
|
||||
*/
|
||||
default String getTeamDisplayName() {
|
||||
String name = getName();
|
||||
Team team = Bukkit.getScoreboardManager().getMainScoreboard().getEntryTeam(name);
|
||||
if (team == null)
|
||||
return null;
|
||||
String teamPrefix = team.getPrefix();
|
||||
String teamSuffix = team.getSuffix();
|
||||
String teamColor = team.getColor().toString();
|
||||
|
||||
return teamPrefix + teamColor + name + teamSuffix;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
package fr.pandacub.lib.paper.players;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.destroystokyo.paper.ClientOption;
|
||||
import com.destroystokyo.paper.ClientOption.ChatVisibility;
|
||||
import com.destroystokyo.paper.SkinParts;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.kyori.adventure.title.Title.Times;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.MainHand;
|
||||
|
||||
import fr.pandacube.lib.players.standalone.StandaloneOnlinePlayer;
|
||||
|
||||
public interface PaperOnlinePlayer extends PaperOffPlayer, StandaloneOnlinePlayer {
|
||||
|
||||
/*
|
||||
* General data and state
|
||||
*/
|
||||
|
||||
@Override
|
||||
default String getName() {
|
||||
return getBukkitPlayer().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
default String getWorldName() {
|
||||
return getBukkitPlayer().getWorld().getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Related class instances
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return l'instance Bukkit du joueur en ligne, ou null si il n'est pas en
|
||||
* ligne
|
||||
*/
|
||||
Player getBukkitPlayer();
|
||||
|
||||
@Override
|
||||
default OfflinePlayer getBukkitOfflinePlayer() {
|
||||
return getBukkitPlayer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Sending packet and stuff to player
|
||||
*/
|
||||
|
||||
@Override
|
||||
default void sendMessage(Component message) {
|
||||
getBukkitPlayer().sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void sendMessage(ComponentLike message, UUID sender) {
|
||||
getBukkitPlayer().sendMessage(sender == null ? Identity.nil() : Identity.identity(sender), message, MessageType.CHAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void sendMessage(Component message, Identified sender) {
|
||||
getBukkitPlayer().sendMessage(sender == null ? Identity.nil() : sender.identity(), message, MessageType.CHAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
default void sendTitle(Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
getBukkitPlayer().showTitle(Title.title(title, subtitle, Times.times(Ticks.duration(fadeIn), Ticks.duration(stay), Ticks.duration(fadeOut))));
|
||||
}
|
||||
|
||||
default void playSound(Sound sound, float volume, float pitch) {
|
||||
playSound(sound, getBukkitPlayer().getLocation(), volume, pitch);
|
||||
}
|
||||
|
||||
default void playSound(Sound sound, Location location, float volume, float pitch) {
|
||||
getBukkitPlayer().playSound(location, sound, volume, pitch);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Client options
|
||||
*/
|
||||
|
||||
@Override
|
||||
PaperClientOptions getClientOptions();
|
||||
|
||||
public abstract class PaperClientOptions implements StandaloneOnlinePlayer.ClientOptions {
|
||||
|
||||
private final PaperOnlinePlayer op;
|
||||
|
||||
public PaperClientOptions(PaperOnlinePlayer op) {
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChatColorEnabled() {
|
||||
return op.getBukkitPlayer().getClientOption(ClientOption.CHAT_COLORS_ENABLED);
|
||||
}
|
||||
|
||||
public ChatVisibility getChatVisibility() {
|
||||
return op.getBukkitPlayer().getClientOption(ClientOption.CHAT_VISIBILITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChatFullyVisible() {
|
||||
ChatVisibility v = getChatVisibility();
|
||||
return v == ChatVisibility.FULL || v == ChatVisibility.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChatOnlyDisplayingSystemMessages() {
|
||||
return getChatVisibility() == ChatVisibility.SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChatHidden() {
|
||||
return getChatVisibility() == ChatVisibility.HIDDEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return op.getBukkitPlayer().locale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewDistance() {
|
||||
return op.getBukkitPlayer().getClientViewDistance();
|
||||
}
|
||||
|
||||
public MainHand getMainHand() {
|
||||
return op.getBukkitPlayer().getMainHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeftHanded() {
|
||||
return getMainHand() == MainHand.LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRightHanded() {
|
||||
return getMainHand() == MainHand.RIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean isTextFilteringEnabled(); // needs reflection
|
||||
|
||||
@Override
|
||||
public boolean allowsServerListing() {
|
||||
return op.getBukkitPlayer().isAllowingServerListings();
|
||||
}
|
||||
|
||||
public SkinParts getSkinParts() {
|
||||
return op.getBukkitPlayer().getClientOption(ClientOption.SKIN_PARTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinCapeEnabled() {
|
||||
return getSkinParts().hasCapeEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinJacketEnabled() {
|
||||
return getSkinParts().hasJacketEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinLeftSleeveEnabled() {
|
||||
return getSkinParts().hasLeftSleeveEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinRightSleeveEnabled() {
|
||||
return getSkinParts().hasRightSleeveEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinLeftPantsEnabled() {
|
||||
return getSkinParts().hasLeftPantsEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinRightPantsEnabled() {
|
||||
return getSkinParts().hasRightPantsEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkinHatsEnabled() {
|
||||
return getSkinParts().hasHatsEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Custom damage
|
||||
*/
|
||||
|
||||
default void damage(double amount) {
|
||||
getBukkitPlayer().damage(amount); // uses DamageSource.GENERIC
|
||||
}
|
||||
|
||||
default void damage(double amount, LivingEntity source) {
|
||||
getBukkitPlayer().damage(amount, source); // uses appropriate DamageSource according to provided player or entity
|
||||
}
|
||||
|
||||
|
||||
}
|
9
pom.xml
9
pom.xml
@ -46,6 +46,8 @@
|
||||
|
||||
<modules>
|
||||
<module>pandalib-bungee</module>
|
||||
<module>pandalib-bungee-permissions</module>
|
||||
<module>pandalib-bungee-players</module>
|
||||
<module>pandalib-chat</module>
|
||||
<module>pandalib-cli</module>
|
||||
<module>pandalib-core</module>
|
||||
@ -53,15 +55,14 @@
|
||||
<module>pandalib-net</module>
|
||||
<module>pandalib-netapi</module>
|
||||
<module>pandalib-paper</module>
|
||||
<module>pandalib-paper-permissions</module>
|
||||
<module>pandalib-paper-players</module>
|
||||
<module>pandalib-paper-reflect</module>
|
||||
<module>pandalib-permissions</module>
|
||||
<module>pandalib-players-permissible</module>
|
||||
<module>pandalib-players-standalone</module>
|
||||
<module>pandalib-reflect</module>
|
||||
<module>pandalib-util</module>
|
||||
<module>pandalib-players-permissible</module>
|
||||
<module>pandalib-bungee-permissions</module>
|
||||
<module>pandalib-bungee-players</module>
|
||||
<module>pandalib-paper-permissions</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
Loading…
Reference in New Issue
Block a user