mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-19 06:32:03 +01:00
Added Player#setResourcePack + PlayerResourcePackStatusEvent
This commit is contained in:
parent
ce89963240
commit
c17aba4ac7
@ -31,6 +31,7 @@ import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.recipe.Recipe;
|
||||
import net.minestom.server.recipe.RecipeManager;
|
||||
import net.minestom.server.resourcepack.ResourcePack;
|
||||
import net.minestom.server.scoreboard.BelowNameScoreboard;
|
||||
import net.minestom.server.scoreboard.Team;
|
||||
import net.minestom.server.sound.Sound;
|
||||
@ -964,6 +965,26 @@ public class Player extends LivingEntity {
|
||||
return !itemDropEvent.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the resource pack of the player
|
||||
*
|
||||
* @param resourcePack the resource pack
|
||||
*/
|
||||
public void setResourcePack(ResourcePack resourcePack) {
|
||||
Check.notNull(resourcePack, "The resource pack cannot be null");
|
||||
final String url = resourcePack.getUrl();
|
||||
Check.notNull(url, "The resource pack url cannot be null");
|
||||
|
||||
// Optional hash, set to empty if null
|
||||
String hash = resourcePack.getHash();
|
||||
hash = hash == null ? "" : hash;
|
||||
|
||||
ResourcePackSendPacket resourcePackSendPacket = new ResourcePackSendPacket();
|
||||
resourcePackSendPacket.url = url;
|
||||
resourcePackSendPacket.hash = hash;
|
||||
playerConnection.sendPacket(resourcePackSendPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the player to face {@code targetPosition}
|
||||
*
|
||||
|
@ -0,0 +1,37 @@
|
||||
package net.minestom.server.event.player;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.resourcepack.ResourcePackStatus;
|
||||
|
||||
/**
|
||||
* Called when a player warns the server of a resource pack status
|
||||
*/
|
||||
public class PlayerResourcePackStatusEvent extends Event {
|
||||
|
||||
private Player player;
|
||||
private ResourcePackStatus status;
|
||||
|
||||
public PlayerResourcePackStatusEvent(Player player, ResourcePackStatus status) {
|
||||
this.player = player;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player who send a resource pack status
|
||||
*
|
||||
* @return the player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource pack status
|
||||
*
|
||||
* @return the resource pack status
|
||||
*/
|
||||
public ResourcePackStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.minestom.server.listener;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerResourcePackStatusEvent;
|
||||
import net.minestom.server.network.packet.client.play.ClientResourcePackStatusPacket;
|
||||
import net.minestom.server.resourcepack.ResourcePackStatus;
|
||||
|
||||
public class ResourcePackListener {
|
||||
|
||||
public static void listener(ClientResourcePackStatusPacket packet, Player player) {
|
||||
ResourcePackStatus result = packet.result;
|
||||
PlayerResourcePackStatusEvent resourcePackStatusEvent = new PlayerResourcePackStatusEvent(player, result);
|
||||
player.callEvent(PlayerResourcePackStatusEvent.class, resourcePackStatusEvent);
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ public class PacketListenerManager {
|
||||
addListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
|
||||
addListener(ClientPlayerAbilitiesPacket.class, AbilitiesListener::listener);
|
||||
addListener(ClientTeleportConfirmPacket.class, TeleportListener::listener);
|
||||
addListener(ClientResourcePackStatusPacket.class, ResourcePackListener::listener);
|
||||
}
|
||||
|
||||
public <T extends ClientPlayPacket> void process(T packet, Player player) {
|
||||
|
@ -2,18 +2,15 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.packet.PacketReader;
|
||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||
import net.minestom.server.resourcepack.ResourcePackStatus;
|
||||
|
||||
public class ClientResourcePackStatusPacket extends ClientPlayPacket {
|
||||
|
||||
public Result result;
|
||||
public ResourcePackStatus result;
|
||||
|
||||
@Override
|
||||
public void read(PacketReader reader) {
|
||||
this.result = Result.values()[reader.readVarInt()];
|
||||
}
|
||||
|
||||
public enum Result {
|
||||
SUCCESS, DECLINED, FAILED_DOWNLOAD, ACCEPTED
|
||||
this.result = ResourcePackStatus.values()[reader.readVarInt()];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package net.minestom.server.resourcepack;
|
||||
|
||||
/**
|
||||
* Represent a resource pack which can be send to a player
|
||||
*/
|
||||
public class ResourcePack {
|
||||
|
||||
private String url;
|
||||
private String hash;
|
||||
|
||||
public ResourcePack(String url, String hash) {
|
||||
this.url = url;
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource pack URL
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource pack hash
|
||||
* <p>
|
||||
* WARNING: if null or empty, the player will probably waste bandwidth by re-downloading
|
||||
* the resource pack
|
||||
*
|
||||
* @return the resource pack hash
|
||||
*/
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package net.minestom.server.resourcepack;
|
||||
|
||||
public enum ResourcePackStatus {
|
||||
SUCCESS, DECLINED, FAILED_DOWNLOAD, ACCEPTED
|
||||
}
|
Loading…
Reference in New Issue
Block a user