mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-19 06:32:03 +01:00
Cleanup
This commit is contained in:
parent
71b2988583
commit
98c3419766
@ -11,6 +11,7 @@ import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.Vector;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
@ -300,44 +301,19 @@ public abstract class EntityCreature extends LivingEntity {
|
||||
*/
|
||||
public void moveTowards(Position direction, float speed) {
|
||||
Check.notNull(direction, "The direction cannot be null");
|
||||
final float currentX = position.getX();
|
||||
final float currentZ = position.getZ();
|
||||
final float targetX = direction.getX();
|
||||
final float targetZ = direction.getZ();
|
||||
final float x = getPosition().getX();
|
||||
final float y = getPosition().getY();
|
||||
final float z = getPosition().getZ();
|
||||
|
||||
final float radians = (float) Math.atan2(targetZ - currentZ, targetX - currentX);
|
||||
final float speedX = (float) (Math.cos(radians) * speed);
|
||||
final float speedZ = (float) (Math.sin(radians) * speed);
|
||||
float dx = (direction.getX() - x);
|
||||
float dy = (direction.getY() - y);
|
||||
float dz = (direction.getZ() - z);
|
||||
|
||||
float finalX = speedX;
|
||||
float finalZ = speedZ;
|
||||
dx = MathUtils.clampFloat(dx, -speed, speed);
|
||||
dy = MathUtils.clampFloat(dy, -speed, speed);
|
||||
dz = MathUtils.clampFloat(dz, -speed, speed);
|
||||
|
||||
//System.out.println("TEST X: " + targetX + " : " + currentX + " : " + speedX);
|
||||
//System.out.println("TEST Z: "+targetZ+" : "+currentZ+" : "+speedZ);
|
||||
|
||||
// X checks
|
||||
/*if (targetX > currentX && currentX + speedX > targetX) {
|
||||
// Try to go further +X
|
||||
finalX = targetX;
|
||||
System.out.println("CHECK 1");
|
||||
} else if (targetX < currentX && currentX + speedX < targetX) {
|
||||
// Try to go further -X
|
||||
finalX = targetX;
|
||||
System.out.println("CHECK 2");
|
||||
}
|
||||
|
||||
// Z checks
|
||||
if (targetZ > currentZ && currentZ + speedZ >= targetZ) {
|
||||
// Try to go further +X
|
||||
finalZ = targetZ;
|
||||
System.out.println("CHECK 3");
|
||||
} else if (targetZ < currentZ && currentZ + speedZ < targetZ) {
|
||||
// Try to go further -X
|
||||
finalZ = targetX;
|
||||
System.out.println("CHECK 4");
|
||||
}*/
|
||||
|
||||
move(finalX, 0, finalZ, true);
|
||||
move(dx, dy, dz, true);
|
||||
}
|
||||
|
||||
private ItemStack getEquipmentItem(ItemStack itemStack, ArmorEquipEvent.ArmorSlot armorSlot) {
|
||||
|
@ -468,7 +468,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
respawnPacket.gameMode = getGameMode();
|
||||
respawnPacket.levelType = getLevelType();
|
||||
getPlayerConnection().sendPacket(respawnPacket);
|
||||
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this, getRespawnPoint());
|
||||
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this);
|
||||
callEvent(PlayerRespawnEvent.class, respawnEvent);
|
||||
refreshIsDead(false);
|
||||
|
||||
@ -2171,7 +2171,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
* @param chatMode the player chat mode
|
||||
* @param chatColors the player chat colors
|
||||
* @param displayedSkinParts the player displayed skin parts
|
||||
* @param mainHand the player main handœ
|
||||
* @param mainHand the player main hand
|
||||
*/
|
||||
public void refresh(String locale, byte viewDistance, ChatMode chatMode, boolean chatColors, byte displayedSkinParts, MainHand mainHand) {
|
||||
this.locale = locale;
|
||||
|
@ -13,9 +13,9 @@ public class PlayerRespawnEvent extends Event {
|
||||
private final Player player;
|
||||
private Position respawnPosition;
|
||||
|
||||
public PlayerRespawnEvent(Player player, Position respawnPosition) {
|
||||
public PlayerRespawnEvent(Player player) {
|
||||
this.player = player;
|
||||
this.respawnPosition = respawnPosition;
|
||||
this.respawnPosition = player.getRespawnPoint();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,6 +29,8 @@ public class PlayerRespawnEvent extends Event {
|
||||
|
||||
/**
|
||||
* Get the respawn position
|
||||
* <p>
|
||||
* Is by default {@link Player#getRespawnPoint()}
|
||||
*
|
||||
* @return the respawn position
|
||||
*/
|
||||
|
@ -9,23 +9,39 @@ public class PacketController {
|
||||
this.packetListenerConsumer = packetListenerConsumer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the packet is cancelled
|
||||
*
|
||||
* @return true if the packet will be cancelled, false otherwise
|
||||
*/
|
||||
public boolean isCancel() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cancel true if the packet should be cancelled
|
||||
* Used to cancel the packet
|
||||
*
|
||||
* @param cancel true if the packet should be cancelled, false otherwise
|
||||
*/
|
||||
public void setCancel(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the listener associated with the packet
|
||||
*
|
||||
* @return the packet's listener
|
||||
*/
|
||||
public PacketListenerConsumer getPacketListenerConsumer() {
|
||||
return packetListenerConsumer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param packetListenerConsumer the new listener (do not override the default listener)
|
||||
* Change the packet listener, setting it to null cancel the listener
|
||||
* <p>
|
||||
* WARNING: this will overwrite the default minestom listener
|
||||
*
|
||||
* @param packetListenerConsumer the new packet listener
|
||||
*/
|
||||
public void setPacketListenerConsumer(PacketListenerConsumer packetListenerConsumer) {
|
||||
this.packetListenerConsumer = packetListenerConsumer;
|
||||
|
@ -17,41 +17,41 @@ public class PacketListenerManager {
|
||||
private Map<Class<? extends ClientPlayPacket>, PacketListenerConsumer> listeners = new ConcurrentHashMap<>();
|
||||
|
||||
public PacketListenerManager() {
|
||||
addListener(ClientKeepAlivePacket.class, KeepAliveListener::listener);
|
||||
addListener(ClientChatMessagePacket.class, ChatMessageListener::listener);
|
||||
addListener(ClientClickWindowPacket.class, WindowListener::clickWindowListener);
|
||||
addListener(ClientCloseWindow.class, WindowListener::closeWindowListener);
|
||||
addListener(ClientWindowConfirmationPacket.class, WindowListener::windowConfirmationListener);
|
||||
addListener(ClientEntityActionPacket.class, EntityActionListener::listener);
|
||||
addListener(ClientHeldItemChangePacket.class, PlayerHeldListener::heldListener);
|
||||
addListener(ClientPlayerBlockPlacementPacket.class, BlockPlacementListener::listener);
|
||||
addListener(ClientSteerVehiclePacket.class, PlayerVehicleListener::steerVehicleListener);
|
||||
addListener(ClientVehicleMovePacket.class, PlayerVehicleListener::vehicleMoveListener);
|
||||
addListener(ClientSteerBoatPacket.class, PlayerVehicleListener::boatSteerListener);
|
||||
addListener(ClientPlayerPacket.class, PlayerPositionListener::playerPacketListener);
|
||||
addListener(ClientPlayerRotationPacket.class, PlayerPositionListener::playerLookListener);
|
||||
addListener(ClientPlayerPositionPacket.class, PlayerPositionListener::playerPositionListener);
|
||||
addListener(ClientPlayerPositionAndRotationPacket.class, PlayerPositionListener::playerPositionAndLookListener);
|
||||
addListener(ClientPlayerDiggingPacket.class, PlayerDiggingListener::playerDiggingListener);
|
||||
addListener(ClientAnimationPacket.class, AnimationListener::animationListener);
|
||||
addListener(ClientInteractEntityPacket.class, UseEntityListener::useEntityListener);
|
||||
addListener(ClientUseItemPacket.class, UseItemListener::useItemListener);
|
||||
addListener(ClientStatusPacket.class, StatusListener::listener);
|
||||
addListener(ClientSettingsPacket.class, SettingsListener::listener);
|
||||
addListener(ClientCreativeInventoryActionPacket.class, CreativeInventoryActionListener::listener);
|
||||
addListener(ClientCraftRecipeRequest.class, RecipeListener::listener);
|
||||
addListener(ClientTabCompletePacket.class, TabCompleteListener::listener);
|
||||
addListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
|
||||
addListener(ClientPlayerAbilitiesPacket.class, AbilitiesListener::listener);
|
||||
addListener(ClientTeleportConfirmPacket.class, TeleportListener::listener);
|
||||
addListener(ClientResourcePackStatusPacket.class, ResourcePackListener::listener);
|
||||
setListener(ClientKeepAlivePacket.class, KeepAliveListener::listener);
|
||||
setListener(ClientChatMessagePacket.class, ChatMessageListener::listener);
|
||||
setListener(ClientClickWindowPacket.class, WindowListener::clickWindowListener);
|
||||
setListener(ClientCloseWindow.class, WindowListener::closeWindowListener);
|
||||
setListener(ClientWindowConfirmationPacket.class, WindowListener::windowConfirmationListener);
|
||||
setListener(ClientEntityActionPacket.class, EntityActionListener::listener);
|
||||
setListener(ClientHeldItemChangePacket.class, PlayerHeldListener::heldListener);
|
||||
setListener(ClientPlayerBlockPlacementPacket.class, BlockPlacementListener::listener);
|
||||
setListener(ClientSteerVehiclePacket.class, PlayerVehicleListener::steerVehicleListener);
|
||||
setListener(ClientVehicleMovePacket.class, PlayerVehicleListener::vehicleMoveListener);
|
||||
setListener(ClientSteerBoatPacket.class, PlayerVehicleListener::boatSteerListener);
|
||||
setListener(ClientPlayerPacket.class, PlayerPositionListener::playerPacketListener);
|
||||
setListener(ClientPlayerRotationPacket.class, PlayerPositionListener::playerLookListener);
|
||||
setListener(ClientPlayerPositionPacket.class, PlayerPositionListener::playerPositionListener);
|
||||
setListener(ClientPlayerPositionAndRotationPacket.class, PlayerPositionListener::playerPositionAndLookListener);
|
||||
setListener(ClientPlayerDiggingPacket.class, PlayerDiggingListener::playerDiggingListener);
|
||||
setListener(ClientAnimationPacket.class, AnimationListener::animationListener);
|
||||
setListener(ClientInteractEntityPacket.class, UseEntityListener::useEntityListener);
|
||||
setListener(ClientUseItemPacket.class, UseItemListener::useItemListener);
|
||||
setListener(ClientStatusPacket.class, StatusListener::listener);
|
||||
setListener(ClientSettingsPacket.class, SettingsListener::listener);
|
||||
setListener(ClientCreativeInventoryActionPacket.class, CreativeInventoryActionListener::listener);
|
||||
setListener(ClientCraftRecipeRequest.class, RecipeListener::listener);
|
||||
setListener(ClientTabCompletePacket.class, TabCompleteListener::listener);
|
||||
setListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
|
||||
setListener(ClientPlayerAbilitiesPacket.class, AbilitiesListener::listener);
|
||||
setListener(ClientTeleportConfirmPacket.class, TeleportListener::listener);
|
||||
setListener(ClientResourcePackStatusPacket.class, ResourcePackListener::listener);
|
||||
}
|
||||
|
||||
public <T extends ClientPlayPacket> void process(T packet, Player player) {
|
||||
|
||||
final Class clazz = packet.getClass();
|
||||
|
||||
final PacketListenerConsumer<T> packetListenerConsumer = listeners.get(clazz);
|
||||
PacketListenerConsumer<T> packetListenerConsumer = listeners.get(clazz);
|
||||
|
||||
// Listener can be null if none has been set before, call PacketConsumer anyway
|
||||
if (packetListenerConsumer == null) {
|
||||
@ -67,6 +67,9 @@ public class PacketListenerManager {
|
||||
if (packetController.isCancel())
|
||||
return;
|
||||
|
||||
// Get the new listener (or the same) from the packet controller
|
||||
packetListenerConsumer = packetController.getPacketListenerConsumer();
|
||||
|
||||
// Call the listener if not null
|
||||
// (can be null because no listener is set, or because it has been changed by the controller)
|
||||
if (packetListenerConsumer != null) {
|
||||
@ -74,7 +77,16 @@ public class PacketListenerManager {
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends ClientPlayPacket> void addListener(Class<T> packetClass, PacketListenerConsumer<T> consumer) {
|
||||
/**
|
||||
* Set the listener of a packet
|
||||
* <p>
|
||||
* WARNING: this will overwrite the default minestom listener, this is not reversible
|
||||
*
|
||||
* @param packetClass the class of the packet
|
||||
* @param consumer the new packet's listener
|
||||
* @param <T> the type of the packet
|
||||
*/
|
||||
public <T extends ClientPlayPacket> void setListener(Class<T> packetClass, PacketListenerConsumer<T> consumer) {
|
||||
this.listeners.put(packetClass, consumer);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user