Move teleport method in FakeEntity, create PacketQueue, split each packet in a dedicated method

This commit is contained in:
Flowsqy 2022-12-31 02:50:56 +01:00
parent 7fc4459d12
commit 91a96d2f33
5 changed files with 99 additions and 13 deletions

View File

@ -1,12 +1,17 @@
package de.epiceric.shopchest.nms;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Represent an ArmorStand that only exists clientside
*/
public interface FakeArmorStand extends FakeEntity {
void sendData(String name, Iterable<Player> receivers);
void setLocation(Location location, Iterable<Player> receivers);
/**
* Register a 'metadata' packet in the {@link PacketQueue}
* <br>
* It sets the invisibility, the custom name, make it visible and the marker flag
*
* @param packetQueue The {@link PacketQueue} to store the packet
*/
void metadata(PacketQueue packetQueue);
}

View File

@ -1,16 +1,44 @@
package de.epiceric.shopchest.nms;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.UUID;
/**
* Represent an entity that only exists clientside
*/
public interface FakeEntity {
/**
* Get entity id
*
* @return The entity id
*/
int getEntityId();
void spawn(UUID uuid, Location location, Iterable<Player> receivers);
/**
* Register a 'create' packet in the {@link PacketQueue}
*
* @param packetQueue The {@link PacketQueue} to store the packet
* @param uuid The {@link UUID} of the entity
* @param location The {@link Location} to spawn the entity
*/
void create(PacketQueue packetQueue, UUID uuid, Location location);
void remove(Iterable<Player> receivers);
/**
* Register a 'remove' packet in the {@link PacketQueue}
*
* @param packetQueue The {@link PacketQueue} to store the packet
*/
void remove(PacketQueue packetQueue);
/**
* Register a 'teleport' packet in the {@link PacketQueue}
*
* @param packetQueue The {@link PacketQueue} to store the packet
* @param position The position to teleport the entity
*/
void teleport(PacketQueue packetQueue, Vector position);
}

View File

@ -1,12 +1,27 @@
package de.epiceric.shopchest.nms;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
* Represent an Item entity that only exists clientside
*/
public interface FakeItem extends FakeEntity {
void sendData(ItemStack item, Iterable<Player> receivers);
/**
* Register a 'metadata' packet in the {@link PacketQueue}
* <br>
* It sets the type of item
*
* @param packetQueue The {@link PacketQueue} to store the packet
* @param item The {@link ItemStack} type
*/
void metadata(PacketQueue packetQueue, ItemStack item);
void resetVelocity(Iterable<Player> receivers);
/**
* Register a zero 'velocity' packet in the {@link PacketQueue} to stop the item from moving
*
* @param packetQueue The {@link PacketQueue} to store the packet
*/
void cancelVelocity(PacketQueue packetQueue);
}

View File

@ -0,0 +1,17 @@
package de.epiceric.shopchest.nms;
import org.bukkit.entity.Player;
/**
* A queue of packet that can be sent
*/
public interface PacketQueue {
/**
* Send all packets to players
*
* @param receivers The {@link Player}s that receives the packets
*/
void send(Iterable<Player> receivers);
}

View File

@ -1,11 +1,32 @@
package de.epiceric.shopchest.nms;
/**
* The platform that create all nms objects
*/
public interface Platform {
/**
* Create a {@link FakeArmorStand} object
*
* @return a new {@link FakeArmorStand}
*/
FakeArmorStand createFakeArmorStand();
/**
* Create a {@link FakeItem} object
*
* @return a new {@link FakeItem}
*/
FakeItem createFakeItem();
/**
* Create a {@link PacketQueue} object
*
* @return a new {@link PacketQueue}
*/
PacketQueue createPacketQueue();
TextComponentHelper getTextComponentHelper();
}