Skip to content

Commit

Permalink
Add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Sep 15, 2024
1 parent 93b0324 commit 6cbf3f5
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Used to add an entity to the client's world.
*/
public abstract class FS_ClientboundAddEntityPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundAddEntityPacket extends FS_ClientboundPacket {

protected int entityId;
protected UUID entityUUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,39 @@
import de.oliver.fancysitula.api.entities.FS_RealPlayer;
import org.jetbrains.annotations.ApiStatus;

public interface FS_ClientboundPacket {
public abstract class FS_ClientboundPacket {

protected static boolean enableDebugLogs = false;

/**
* Enables debug logs for all packets.
*/
public static void enableDebugLogs() {
enableDebugLogs = true;
}

/**
* Creates the packet object.
* For internal use only.
*/
@ApiStatus.Internal
Object createPacket();
public abstract Object createPacket();

/**
* Sends the packet to the player.
*
* @param player the player to send the packet to
* For internal use only.
*/
void send(FS_RealPlayer player);
@ApiStatus.Internal
protected abstract void sendPacketTo(FS_RealPlayer player);

/**
* Sends the packet to the player.
*/
public final void send(FS_RealPlayer player) {
if (enableDebugLogs) {
System.out.println("Sending packet '" + this.getClass().getSimpleName() + "' to " + player.getBukkitPlayer().getName());
}

sendPacketTo(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Used to remove players from the client's player list.
*/
public abstract class FS_ClientboundPlayerInfoRemovePacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundPlayerInfoRemovePacket extends FS_ClientboundPacket {

protected List<UUID> uuids;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Used to update the player list of the client.
*/
public abstract class FS_ClientboundPlayerInfoUpdatePacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundPlayerInfoUpdatePacket extends FS_ClientboundPacket {

protected EnumSet<Action> actions;
protected List<Entry> entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Used to remove entities from the client's world.
*/
public abstract class FS_ClientboundRemoveEntitiesPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundRemoveEntitiesPacket extends FS_ClientboundPacket {

protected List<Integer> entityIds;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.oliver.fancysitula.api.packets;

public abstract class FS_ClientboundRotateHeadPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundRotateHeadPacket extends FS_ClientboundPacket {

protected int entityId;
protected float headYaw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

public abstract class FS_ClientboundSetEntityDataPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundSetEntityDataPacket extends FS_ClientboundPacket {

protected int entityId;
protected List<EntityData> entityData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.Map;

public abstract class FS_ClientboundSetEquipmentPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundSetEquipmentPacket extends FS_ClientboundPacket {

protected int entityId;
protected Map<FS_EquipmentSlot, ItemStack> equipment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

public abstract class FS_ClientboundSetPassengersPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundSetPassengersPacket extends FS_ClientboundPacket {

protected int entityId;
protected List<Integer> passengers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.oliver.fancysitula.api.packets;

public abstract class FS_ClientboundTeleportEntityPacket implements FS_ClientboundPacket {
public abstract class FS_ClientboundTeleportEntityPacket extends FS_ClientboundPacket {

protected int entityId;
protected double x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundAddEntityPacket packet = (ClientboundAddEntityPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundPlayerInfoRemovePacket packet = (ClientboundPlayerInfoRemovePacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundPlayerInfoUpdatePacket packet = (ClientboundPlayerInfoUpdatePacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundRemoveEntitiesPacket packet = (ClientboundRemoveEntitiesPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundRotateHeadPacket packet = (ClientboundRotateHeadPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundSetEquipmentPacket packet = (ClientboundSetEquipmentPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundSetPassengersPacket packet = (ClientboundSetPassengersPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Object createPacket() {
}

@Override
public void send(FS_RealPlayer player) {
public void sendPacketTo(FS_RealPlayer player) {
ClientboundTeleportEntityPacket packet = (ClientboundTeleportEntityPacket) createPacket();

ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package de.oliver.fancysitula;

import de.oliver.fancysitula.api.packets.FS_ClientboundPacket;
import de.oliver.fancysitula.commands.FancySitulaCMD;
import org.bukkit.plugin.java.JavaPlugin;

public class FancySitulaPlugin extends JavaPlugin {

@Override
public void onEnable() {
FS_ClientboundPacket.enableDebugLogs();

getServer().getCommandMap().register("fancysitula", new FancySitulaCMD());
}
}

0 comments on commit 6cbf3f5

Please sign in to comment.