-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2393b87
commit ba51781
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
api/src/main/java/de/oliver/fancysitula/api/packets/FS_ClientboundSetPassengersPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.oliver.fancysitula.api.packets; | ||
|
||
import java.util.List; | ||
|
||
public abstract class FS_ClientboundSetPassengersPacket implements FS_ClientboundPacket { | ||
|
||
protected int entityId; | ||
protected List<Integer> passengers; | ||
|
||
public FS_ClientboundSetPassengersPacket(int entityId, List<Integer> passengers) { | ||
this.entityId = entityId; | ||
this.passengers = passengers; | ||
} | ||
|
||
public int getEntityId() { | ||
return entityId; | ||
} | ||
|
||
public void setEntityId(int entityId) { | ||
this.entityId = entityId; | ||
} | ||
|
||
public List<Integer> getPassengers() { | ||
return passengers; | ||
} | ||
|
||
public void setPassengers(List<Integer> passengers) { | ||
this.passengers = passengers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...va/de/oliver/fancysitula/versions/v1_20_6/packets/ClientboundSetPassengersPacketImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.oliver.fancysitula.versions.v1_20_6.packets; | ||
|
||
import de.oliver.fancysitula.api.entities.FS_RealPlayer; | ||
import de.oliver.fancysitula.api.packets.FS_ClientboundSetPassengersPacket; | ||
import de.oliver.fancysitula.api.utils.reflections.ReflectionUtils; | ||
import de.oliver.fancysitula.versions.v1_20_6.utils.VanillaPlayerAdapter; | ||
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
import java.util.List; | ||
|
||
public class ClientboundSetPassengersPacketImpl extends FS_ClientboundSetPassengersPacket { | ||
|
||
public ClientboundSetPassengersPacketImpl(int entityId, List<Integer> passengers) { | ||
super(entityId, passengers); | ||
} | ||
|
||
|
||
@Override | ||
public Object createPacket() { | ||
int[] passengers = new int[this.passengers.size()]; | ||
for (int i = 0; i < this.passengers.size(); i++) { | ||
passengers[i] = this.passengers.get(i); | ||
} | ||
|
||
try { | ||
ClientboundSetPassengersPacket packet = ReflectionUtils.createUnsafeInstance(ClientboundSetPassengersPacket.class); | ||
ReflectionUtils.setFinalField(packet, "vehicle", entityId); | ||
ReflectionUtils.setFinalField(packet, "passengers", passengers); | ||
return packet; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void send(FS_RealPlayer player) { | ||
ClientboundSetPassengersPacket packet = (ClientboundSetPassengersPacket) createPacket(); | ||
|
||
ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); | ||
vanillaPlayer.connection.send(packet); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...e/oliver/fancysitula/versions/v1_20_6/packets/ClientboundSetPassengersPacketImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package de.oliver.fancysitula.versions.v1_20_6.packets; | ||
|
||
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ClientboundSetPassengersPacketImplTest { | ||
|
||
@Test | ||
void createPacket() { | ||
// Setup packet | ||
int vehicleID = 712; | ||
List<Integer> passengers = new ArrayList<>(); | ||
passengers.add(571); | ||
passengers.add(572); | ||
|
||
ClientboundSetPassengersPacketImpl packet = new ClientboundSetPassengersPacketImpl(vehicleID, passengers); | ||
ClientboundSetPassengersPacket createdPacket = (ClientboundSetPassengersPacket) packet.createPacket(); | ||
|
||
// Check packet | ||
assert createdPacket.getVehicle() == vehicleID; | ||
assert createdPacket.getPassengers().length == 2; | ||
assert createdPacket.getPassengers()[0] == 571; | ||
assert createdPacket.getPassengers()[1] == 572; | ||
} | ||
} |