-
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
0f314ca
commit 2393b87
Showing
10 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
api/src/main/java/de/oliver/fancysitula/api/entities/FS_Player.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,31 @@ | ||
package de.oliver.fancysitula.api.entities; | ||
|
||
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class FS_Player extends FS_Entity { | ||
|
||
protected Map<FS_EquipmentSlot, ItemStack> equipment; | ||
|
||
public FS_Player() { | ||
super(EntityType.PLAYER); | ||
|
||
this.equipment = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public Map<FS_EquipmentSlot, ItemStack> getEquipment() { | ||
return equipment; | ||
} | ||
|
||
public void setEquipment(Map<FS_EquipmentSlot, ItemStack> equipment) { | ||
this.equipment = equipment; | ||
} | ||
|
||
public void setEquipment(FS_EquipmentSlot slot, ItemStack item) { | ||
this.equipment.put(slot, item); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
api/src/main/java/de/oliver/fancysitula/api/packets/FS_ClientboundSetEquipmentPacket.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,33 @@ | ||
package de.oliver.fancysitula.api.packets; | ||
|
||
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Map; | ||
|
||
public abstract class FS_ClientboundSetEquipmentPacket implements FS_ClientboundPacket { | ||
|
||
protected int entityId; | ||
protected Map<FS_EquipmentSlot, ItemStack> equipment; | ||
|
||
public FS_ClientboundSetEquipmentPacket(int entityId, Map<FS_EquipmentSlot, ItemStack> equipment) { | ||
this.entityId = entityId; | ||
this.equipment = equipment; | ||
} | ||
|
||
public int getEntityId() { | ||
return entityId; | ||
} | ||
|
||
public void setEntityId(int entityId) { | ||
this.entityId = entityId; | ||
} | ||
|
||
public Map<FS_EquipmentSlot, ItemStack> getEquipment() { | ||
return equipment; | ||
} | ||
|
||
public void setEquipment(Map<FS_EquipmentSlot, ItemStack> equipment) { | ||
this.equipment = equipment; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
api/src/main/java/de/oliver/fancysitula/api/utils/FS_EquipmentSlot.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,24 @@ | ||
package de.oliver.fancysitula.api.utils; | ||
|
||
public enum FS_EquipmentSlot { | ||
MAINHAND, | ||
OFFHAND, | ||
FEET, | ||
LEGS, | ||
CHEST, | ||
HEAD, | ||
BODY, | ||
; | ||
|
||
public static FS_EquipmentSlot fromBukkit(org.bukkit.inventory.EquipmentSlot equipmentSlot) { | ||
return switch (equipmentSlot) { | ||
case HAND -> MAINHAND; | ||
case OFF_HAND -> OFFHAND; | ||
case FEET -> FEET; | ||
case LEGS -> LEGS; | ||
case CHEST -> CHEST; | ||
case HEAD -> HEAD; | ||
case BODY -> BODY; | ||
}; | ||
} | ||
} |
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
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
...ava/de/oliver/fancysitula/versions/v1_20_6/packets/ClientboundSetEquipmentPacketImpl.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 com.mojang.datafixers.util.Pair; | ||
import de.oliver.fancysitula.api.entities.FS_RealPlayer; | ||
import de.oliver.fancysitula.api.packets.FS_ClientboundSetEquipmentPacket; | ||
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import de.oliver.fancysitula.versions.v1_20_6.utils.VanillaPlayerAdapter; | ||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.EquipmentSlot; | ||
import org.bukkit.craftbukkit.inventory.CraftItemStack; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ClientboundSetEquipmentPacketImpl extends FS_ClientboundSetEquipmentPacket { | ||
|
||
public ClientboundSetEquipmentPacketImpl(int entityId, Map<FS_EquipmentSlot, ItemStack> equipment) { | ||
super(entityId, equipment); | ||
} | ||
|
||
@Override | ||
public Object createPacket() { | ||
List<Pair<net.minecraft.world.entity.EquipmentSlot, net.minecraft.world.item.ItemStack>> slots = new ArrayList<>(); | ||
|
||
for (Map.Entry<FS_EquipmentSlot, ItemStack> entry : equipment.entrySet()) { | ||
EquipmentSlot equipmentSlot = net.minecraft.world.entity.EquipmentSlot.byName(entry.getKey().name().toLowerCase()); | ||
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(entry.getValue()); | ||
|
||
slots.add(Pair.of(equipmentSlot, itemStack)); | ||
} | ||
|
||
return new ClientboundSetEquipmentPacket(entityId, slots); | ||
} | ||
|
||
@Override | ||
public void send(FS_RealPlayer player) { | ||
ClientboundSetEquipmentPacket packet = (ClientboundSetEquipmentPacket) createPacket(); | ||
|
||
ServerPlayer vanillaPlayer = VanillaPlayerAdapter.asVanilla(player.getBukkitPlayer()); | ||
vanillaPlayer.connection.send(packet); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...de/oliver/fancysitula/versions/v1_20_6/packets/ClientboundSetEquipmentPacketImplTest.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 de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Map; | ||
|
||
class ClientboundSetEquipmentPacketImplTest { | ||
|
||
//TODO: Fix this test (registry problems) | ||
// @Test | ||
void createPacket() { | ||
// Setup packet | ||
Map<FS_EquipmentSlot, ItemStack> equipment = Map.of( | ||
FS_EquipmentSlot.MAINHAND, new ItemStack(Material.DIAMOND_SWORD), | ||
FS_EquipmentSlot.OFFHAND, new ItemStack(Material.SHIELD), | ||
FS_EquipmentSlot.HEAD, new ItemStack(Material.DIAMOND_HELMET) | ||
); | ||
|
||
ClientboundSetEquipmentPacketImpl packet = new ClientboundSetEquipmentPacketImpl(42, equipment); | ||
ClientboundSetEquipmentPacket createdPacket = (ClientboundSetEquipmentPacket) packet.createPacket(); | ||
|
||
assert createdPacket.getEntity() == 42; | ||
assert createdPacket.getSlots().size() == 3; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
implementations/1_21/src/test/java/packets/ClientboundSetEquipmentPacketImplTest.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,29 @@ | ||
package packets; | ||
|
||
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEquipmentPacketImpl; | ||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Map; | ||
|
||
class ClientboundSetEquipmentPacketImplTest { | ||
|
||
//TODO: Fix this test (registry problems) | ||
// @Test | ||
void createPacket() { | ||
// Setup packet | ||
Map<FS_EquipmentSlot, ItemStack> equipment = Map.of( | ||
FS_EquipmentSlot.MAINHAND, new ItemStack(Material.DIAMOND_SWORD), | ||
FS_EquipmentSlot.OFFHAND, new ItemStack(Material.SHIELD), | ||
FS_EquipmentSlot.HEAD, new ItemStack(Material.DIAMOND_HELMET) | ||
); | ||
|
||
ClientboundSetEquipmentPacketImpl packet = new ClientboundSetEquipmentPacketImpl(42, equipment); | ||
ClientboundSetEquipmentPacket createdPacket = (ClientboundSetEquipmentPacket) packet.createPacket(); | ||
|
||
assert createdPacket.getEntity() == 42; | ||
assert createdPacket.getSlots().size() == 3; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
implementations/1_21_1/src/test/java/packets/ClientboundSetEquipmentPacketImplTest.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,29 @@ | ||
package packets; | ||
|
||
import de.oliver.fancysitula.api.utils.FS_EquipmentSlot; | ||
import de.oliver.fancysitula.versions.v1_20_6.packets.ClientboundSetEquipmentPacketImpl; | ||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.util.Map; | ||
|
||
class ClientboundSetEquipmentPacketImplTest { | ||
|
||
//TODO: Fix this test (registry problems) | ||
// @Test | ||
void createPacket() { | ||
// Setup packet | ||
Map<FS_EquipmentSlot, ItemStack> equipment = Map.of( | ||
FS_EquipmentSlot.MAINHAND, new ItemStack(Material.DIAMOND_SWORD), | ||
FS_EquipmentSlot.OFFHAND, new ItemStack(Material.SHIELD), | ||
FS_EquipmentSlot.HEAD, new ItemStack(Material.DIAMOND_HELMET) | ||
); | ||
|
||
ClientboundSetEquipmentPacketImpl packet = new ClientboundSetEquipmentPacketImpl(42, equipment); | ||
ClientboundSetEquipmentPacket createdPacket = (ClientboundSetEquipmentPacket) packet.createPacket(); | ||
|
||
assert createdPacket.getEntity() == 42; | ||
assert createdPacket.getSlots().size() == 3; | ||
} | ||
} |