feat: use packetevents
This commit is contained in:
parent
d17aadc09a
commit
fd732fc886
5 changed files with 220 additions and 63 deletions
164
dependency-reduced-pom.xml
Normal file
164
dependency-reduced-pom.xml
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
<?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/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>net.artelnatif</groupId>
|
||||||
|
<artifactId>nicko</artifactId>
|
||||||
|
<name>Nicko</name>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>${basedir}/src/main/resources/</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M7</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>net.wesjd:anvilgui</include>
|
||||||
|
<include>xyz.xenondevs.invui:*</include>
|
||||||
|
<include>com.github.jsixface:*</include>
|
||||||
|
<include>com.fasterxml.jackson.dataformat</include>
|
||||||
|
<include>com.fasterxml.jackson.core</include>
|
||||||
|
<include>org.mariadb.jdbc</include>
|
||||||
|
</includes>
|
||||||
|
</artifactSet>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.wesjd.anvilgui</pattern>
|
||||||
|
<shadedPattern>net.artelnatif.libs.anvilgui</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>xyz.xenondevs.invui</pattern>
|
||||||
|
<shadedPattern>net.artelnatif.libs.invui</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.github.jsixface</pattern>
|
||||||
|
<shadedPattern>net.artelnatif.libs.yaml</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.fasterxml.jackson.dataformat</pattern>
|
||||||
|
<shadedPattern>net.artelnatif.libs.jackson.yaml</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.fasterxml.jackson.core</pattern>
|
||||||
|
<shadedPattern>net.artelnatif.libs.jackson.core</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.mariadb.jdbc</pattern>
|
||||||
|
<shadedPattern>net.artelnatif.libs.mariadb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
<minimizeJar>false</minimizeJar>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>codemc-snapshots</id>
|
||||||
|
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.retrooper.packetevents</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>31.1-jre</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.seeseemelk</groupId>
|
||||||
|
<artifactId>MockBukkit-v1.19</artifactId>
|
||||||
|
<version>2.29.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>hamcrest-library</artifactId>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>maven-resolver-provider</artifactId>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>maven-resolver-connector-basic</artifactId>
|
||||||
|
<groupId>org.apache.maven.resolver</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>maven-resolver-transport-http</artifactId>
|
||||||
|
<groupId>org.apache.maven.resolver</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>4.3.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
</project>
|
10
pom.xml
10
pom.xml
|
@ -16,10 +16,6 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>dmulloy2-repo</id>
|
|
||||||
<url>https://repo.dmulloy2.net/repository/public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>papermc</id>
|
<id>papermc</id>
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
@ -40,9 +36,9 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.github.retrooper.packetevents</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>5.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- PlaceHolder API -->
|
<!-- PlaceHolder API -->
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.artelnatif.nicko;
|
package net.artelnatif.nicko;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
|
||||||
import net.artelnatif.nicko.command.NickoCommand;
|
import net.artelnatif.nicko.command.NickoCommand;
|
||||||
import net.artelnatif.nicko.config.Configuration;
|
import net.artelnatif.nicko.config.Configuration;
|
||||||
import net.artelnatif.nicko.config.ConfigurationManager;
|
import net.artelnatif.nicko.config.ConfigurationManager;
|
||||||
|
@ -39,7 +37,6 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
private LocaleFileManager localeFileManager;
|
private LocaleFileManager localeFileManager;
|
||||||
private PlayerNameStore nameStore;
|
private PlayerNameStore nameStore;
|
||||||
private ProtocolManager protocolManager;
|
|
||||||
|
|
||||||
public NickoBukkit() { this.unitTesting = false; }
|
public NickoBukkit() { this.unitTesting = false; }
|
||||||
|
|
||||||
|
@ -66,7 +63,6 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
configurationManager = new ConfigurationManager(getDataFolder());
|
configurationManager = new ConfigurationManager(getDataFolder());
|
||||||
configurationManager.saveDefaultConfig();
|
configurationManager.saveDefaultConfig();
|
||||||
|
|
||||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
|
||||||
mojangAPI = new MojangAPI();
|
mojangAPI = new MojangAPI();
|
||||||
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
|
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
|
||||||
nameStore = new PlayerNameStore();
|
nameStore = new PlayerNameStore();
|
||||||
|
@ -154,6 +150,4 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
public LocaleFileManager getLocaleFileManager() {
|
public LocaleFileManager getLocaleFileManager() {
|
||||||
return localeFileManager;
|
return localeFileManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtocolManager getProtocolManager() { return protocolManager; }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package net.artelnatif.nicko.appearance;
|
package net.artelnatif.nicko.appearance;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.github.retrooper.packetevents.protocol.player.TextureProperty;
|
||||||
import com.comphenix.protocol.wrappers.*;
|
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||||
import com.google.common.collect.Multimap;
|
import com.github.retrooper.packetevents.protocol.world.Difficulty;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoUpdate;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRespawn;
|
||||||
|
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||||
import net.artelnatif.nicko.NickoBukkit;
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
import net.artelnatif.nicko.disguise.ActionResult;
|
import net.artelnatif.nicko.disguise.ActionResult;
|
||||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||||
|
@ -12,14 +16,15 @@ import net.artelnatif.nicko.mojang.MojangAPI;
|
||||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||||
import net.artelnatif.nicko.storage.name.PlayerNameStore;
|
import net.artelnatif.nicko.storage.name.PlayerNameStore;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@ -99,16 +104,17 @@ public class AppearanceManager {
|
||||||
|
|
||||||
public ActionResult<Void> updatePlayer(boolean skinChange) {
|
public ActionResult<Void> updatePlayer(boolean skinChange) {
|
||||||
final String displayName = profile.getName() == null ? player.getName() : profile.getName();
|
final String displayName = profile.getName() == null ? player.getName() : profile.getName();
|
||||||
final WrappedGameProfile gameProfile = new WrappedGameProfile(player.getUniqueId(), displayName);
|
Bukkit.broadcastMessage("Building UserProfile");
|
||||||
|
final UserProfile userProfile = new UserProfile(player.getUniqueId(), displayName);
|
||||||
|
|
||||||
final ActionResult<Void> result = updateGameProfileSkin(gameProfile, skinChange);
|
final ActionResult<Void> result = updateGameProfileSkin(userProfile, skinChange);
|
||||||
if (!result.isError()) {
|
if (!result.isError()) {
|
||||||
updateTabList(gameProfile, displayName);
|
updateTabList(userProfile, displayName);
|
||||||
}
|
}
|
||||||
return new ActionResult<>();
|
return new ActionResult<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionResult<Void> updateGameProfileSkin(WrappedGameProfile gameProfile, boolean skinChange) {
|
private ActionResult<Void> updateGameProfileSkin(UserProfile userProfile, boolean skinChange) {
|
||||||
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
|
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
|
||||||
|
|
||||||
if (skinChange || changeOnlyName) {
|
if (skinChange || changeOnlyName) {
|
||||||
|
@ -120,9 +126,9 @@ public class AppearanceManager {
|
||||||
skin = mojang.getSkin(uuid.get());
|
skin = mojang.getSkin(uuid.get());
|
||||||
if (skin.isPresent()) {
|
if (skin.isPresent()) {
|
||||||
final MojangSkin skinResult = skin.get();
|
final MojangSkin skinResult = skin.get();
|
||||||
final Multimap<String, WrappedSignedProperty> properties = gameProfile.getProperties();
|
final List<TextureProperty> properties = userProfile.getTextureProperties();
|
||||||
properties.removeAll("textures");
|
properties.clear();
|
||||||
properties.put("textures", new WrappedSignedProperty("textures", skinResult.getValue(), skinResult.getSignature()));
|
properties.add(new TextureProperty("textures", skinResult.getValue(), skinResult.getSignature()));
|
||||||
Bukkit.broadcastMessage("Modified properties");
|
Bukkit.broadcastMessage("Modified properties");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,47 +145,43 @@ public class AppearanceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void respawnPlayer() {
|
private void respawnPlayer() {
|
||||||
final PacketContainer respawnOtherWorld = getRespawnPacket(Bukkit.getWorld("world_the_end"));
|
final World world = player.getWorld();
|
||||||
final PacketContainer respawn = getRespawnPacket(player.getWorld());
|
final WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(
|
||||||
instance.getProtocolManager().sendServerPacket(player, respawnOtherWorld);
|
SpigotConversionUtil.fromBukkitWorld(world),
|
||||||
instance.getProtocolManager().sendServerPacket(player, respawn);
|
world.getName(),
|
||||||
|
Difficulty.getById(world.getDifficulty().ordinal()),
|
||||||
|
world.getSeed(),
|
||||||
|
SpigotConversionUtil.fromBukkitGameMode(player.getGameMode()),
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
PacketEvents.getAPI().getPlayerManager().sendPacket(player, respawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getRespawnPacket(World world) {
|
private void updateTabList(UserProfile userProfile, String displayName) {
|
||||||
final PacketContainer packet = new PacketContainer(PacketType.Play.Server.RESPAWN);
|
final WrapperPlayServerPlayerInfoUpdate infoAdd = new WrapperPlayServerPlayerInfoUpdate(EnumSet.of(
|
||||||
final EnumWrappers.NativeGameMode gamemode = EnumWrappers.NativeGameMode.fromBukkit(player.getGameMode());
|
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
|
||||||
packet.getWorldKeys().write(0, world);
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_GAME_MODE,
|
||||||
packet.getLongs().write(0, world.getSeed());
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_DISPLAY_NAME,
|
||||||
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_LISTED,
|
||||||
packet.getGameModes().write(0, gamemode); // gamemode
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_LATENCY
|
||||||
packet.getGameModes().write(1, gamemode); // previous gamemode
|
), new WrapperPlayServerPlayerInfoUpdate.PlayerInfo(
|
||||||
|
userProfile,
|
||||||
packet.getBooleans().write(0, false);
|
true,
|
||||||
packet.getBooleans().write(1, false);
|
0,
|
||||||
return packet;
|
SpigotConversionUtil.fromBukkitGameMode(player.getGameMode()),
|
||||||
}
|
Component.text(displayName),
|
||||||
|
null
|
||||||
private void updateTabList(WrappedGameProfile gameProfile, String displayName) {
|
|
||||||
final PacketContainer infoAdd = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
|
||||||
infoAdd.getPlayerInfoActions().write(0, Set.of(
|
|
||||||
EnumWrappers.PlayerInfoAction.ADD_PLAYER,
|
|
||||||
EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE,
|
|
||||||
EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME,
|
|
||||||
EnumWrappers.PlayerInfoAction.UPDATE_LISTED,
|
|
||||||
EnumWrappers.PlayerInfoAction.UPDATE_LATENCY
|
|
||||||
));
|
));
|
||||||
|
|
||||||
infoAdd.getPlayerInfoDataLists().write(1, List.of(new PlayerInfoData(
|
final WrapperPlayServerPlayerInfoRemove infoRemove = new WrapperPlayServerPlayerInfoRemove(player.getUniqueId());
|
||||||
gameProfile,
|
Bukkit.broadcastMessage("Updating tablist");
|
||||||
0,
|
PacketEvents.getAPI().getPlayerManager().sendPacket(player, infoRemove);
|
||||||
EnumWrappers.NativeGameMode.fromBukkit(player.getGameMode()),
|
PacketEvents.getAPI().getPlayerManager().sendPacket(player, infoAdd);
|
||||||
WrappedChatComponent.fromText(displayName)
|
|
||||||
)));
|
|
||||||
|
|
||||||
final PacketContainer infoRemove = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
|
|
||||||
infoRemove.getUUIDLists().write(0, List.of(player.getUniqueId()));
|
|
||||||
|
|
||||||
instance.getProtocolManager().broadcastServerPacket(infoRemove);
|
|
||||||
instance.getProtocolManager().broadcastServerPacket(infoAdd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@ version: 1.0-SNAPSHOT
|
||||||
author: Ineanto
|
author: Ineanto
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
softdepend: [ PlaceholderAPI ]
|
softdepend: [ PlaceholderAPI ]
|
||||||
depend: [ ProtocolLib ]
|
load: POSTWORLD
|
||||||
|
depend: [ packetevents ]
|
||||||
commands:
|
commands:
|
||||||
nicko:
|
nicko:
|
||||||
description: "Opens Nicko's GUI."
|
description: "Opens Nicko's GUI."
|
||||||
|
|
Loading…
Reference in a new issue