mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-30 12:01:26 +01:00
Fixed Held packet + replaced the short by a byte
This commit is contained in:
parent
b47efa35ca
commit
19fc90e764
@ -48,6 +48,6 @@ dependencies {
|
|||||||
api 'net.kyori:text-serializer-plain:3.0.3'
|
api 'net.kyori:text-serializer-plain:3.0.3'
|
||||||
|
|
||||||
// Pathfinding
|
// Pathfinding
|
||||||
implementation 'com.github.MadMartian:hydrazine-path-finding:1.02'
|
implementation 'com.github.MadMartian:hydrazine-path-finding:1.1.0'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -212,6 +212,7 @@ public class PlayerInit {
|
|||||||
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||||
player.sendMessage("CLICK PLAYER INVENTORY");
|
player.sendMessage("CLICK PLAYER INVENTORY");
|
||||||
System.out.println("slot player: " + slot);
|
System.out.println("slot player: " + slot);
|
||||||
|
p.closeInventory();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*Sidebar scoreboard = new Sidebar("Scoreboard Title");
|
/*Sidebar scoreboard = new Sidebar("Scoreboard Title");
|
||||||
@ -225,9 +226,11 @@ public class PlayerInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
player.teleport(new Position(0, 41f, 0));
|
player.teleport(new Position(0, 41f, 0));
|
||||||
|
|
||||||
|
player.setHeldItemSlot((byte) 5);
|
||||||
|
|
||||||
player.setGlowing(true);
|
player.setGlowing(true);
|
||||||
|
|
||||||
ItemStack item = new ItemStack(Material.STONE_SWORD, (byte) 1);
|
ItemStack item = new ItemStack(Material.STONE_SWORD, (byte) 1);
|
||||||
|
@ -84,7 +84,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
// Used internally to allow the closing of inventory within the inventory listener
|
// Used internally to allow the closing of inventory within the inventory listener
|
||||||
private boolean didCloseInventory;
|
private boolean didCloseInventory;
|
||||||
|
|
||||||
private short heldSlot;
|
private byte heldSlot;
|
||||||
|
|
||||||
private Position respawnPoint;
|
private Position respawnPoint;
|
||||||
|
|
||||||
@ -1290,7 +1290,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
* @param slot the slot that the player has to held
|
* @param slot the slot that the player has to held
|
||||||
* @throws IllegalArgumentException if {@code slot} is not between 0 and 8
|
* @throws IllegalArgumentException if {@code slot} is not between 0 and 8
|
||||||
*/
|
*/
|
||||||
public void setHeldItemSlot(short slot) {
|
public void setHeldItemSlot(byte slot) {
|
||||||
Check.argCondition(!MathUtils.isBetween(slot, 0, 8), "Slot has to be between 0 and 8");
|
Check.argCondition(!MathUtils.isBetween(slot, 0, 8), "Slot has to be between 0 and 8");
|
||||||
|
|
||||||
HeldItemChangePacket heldItemChangePacket = new HeldItemChangePacket();
|
HeldItemChangePacket heldItemChangePacket = new HeldItemChangePacket();
|
||||||
@ -1304,7 +1304,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
*
|
*
|
||||||
* @return the current held slot for the player
|
* @return the current held slot for the player
|
||||||
*/
|
*/
|
||||||
public short getHeldSlot() {
|
public byte getHeldSlot() {
|
||||||
return heldSlot;
|
return heldSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1738,11 +1738,11 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
* Also cancel eating if {@link #isEating()} was true
|
* Also cancel eating if {@link #isEating()} was true
|
||||||
* <p>
|
* <p>
|
||||||
* Warning: the player will not be noticed by this chance, only his viewers,
|
* Warning: the player will not be noticed by this chance, only his viewers,
|
||||||
* see instead: {@link #setHeldItemSlot(short)}
|
* see instead: {@link #setHeldItemSlot(byte)}
|
||||||
*
|
*
|
||||||
* @param slot the new held slot
|
* @param slot the new held slot
|
||||||
*/
|
*/
|
||||||
public void refreshHeldSlot(short slot) {
|
public void refreshHeldSlot(byte slot) {
|
||||||
this.heldSlot = slot;
|
this.heldSlot = slot;
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.MAIN_HAND);
|
syncEquipment(EntityEquipmentPacket.Slot.MAIN_HAND);
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ import net.minestom.server.utils.validate.Check;
|
|||||||
public class PlayerChangeHeldSlotEvent extends CancellableEvent {
|
public class PlayerChangeHeldSlotEvent extends CancellableEvent {
|
||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private short slot;
|
private byte slot;
|
||||||
|
|
||||||
public PlayerChangeHeldSlotEvent(Player player, short slot) {
|
public PlayerChangeHeldSlotEvent(Player player, byte slot) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ public class PlayerChangeHeldSlotEvent extends CancellableEvent {
|
|||||||
*
|
*
|
||||||
* @return the held slot
|
* @return the held slot
|
||||||
*/
|
*/
|
||||||
public short getSlot() {
|
public byte getSlot() {
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class PlayerChangeHeldSlotEvent extends CancellableEvent {
|
|||||||
* @param slot the new held slot
|
* @param slot the new held slot
|
||||||
* @throws IllegalArgumentException if {@param slot} is not between 0 and 8
|
* @throws IllegalArgumentException if {@param slot} is not between 0 and 8
|
||||||
*/
|
*/
|
||||||
public void setSlot(short slot) {
|
public void setSlot(byte slot) {
|
||||||
Check.argCondition(!MathUtils.isBetween(slot, 0, 8), "The held slot needs to be between 0 and 8");
|
Check.argCondition(!MathUtils.isBetween(slot, 0, 8), "The held slot needs to be between 0 and 8");
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
}
|
}
|
||||||
|
@ -8,19 +8,20 @@ import net.minestom.server.utils.MathUtils;
|
|||||||
public class PlayerHeldListener {
|
public class PlayerHeldListener {
|
||||||
|
|
||||||
public static void heldListener(ClientHeldItemChangePacket packet, Player player) {
|
public static void heldListener(ClientHeldItemChangePacket packet, Player player) {
|
||||||
final short slot = packet.slot;
|
if (!MathUtils.isBetween(packet.slot, 0, 8)) {
|
||||||
if (!MathUtils.isBetween(slot, 0, 8)) {
|
|
||||||
// Incorrect packet, ignore
|
// Incorrect packet, ignore
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final byte slot = (byte) packet.slot;
|
||||||
|
|
||||||
PlayerChangeHeldSlotEvent changeHeldSlotEvent = new PlayerChangeHeldSlotEvent(player, slot);
|
PlayerChangeHeldSlotEvent changeHeldSlotEvent = new PlayerChangeHeldSlotEvent(player, slot);
|
||||||
player.callEvent(PlayerChangeHeldSlotEvent.class, changeHeldSlotEvent);
|
player.callEvent(PlayerChangeHeldSlotEvent.class, changeHeldSlotEvent);
|
||||||
|
|
||||||
if (!changeHeldSlotEvent.isCancelled()) {
|
if (!changeHeldSlotEvent.isCancelled()) {
|
||||||
// Event hasn't been canceled, process it
|
// Event hasn't been canceled, process it
|
||||||
|
|
||||||
final short resultSlot = changeHeldSlotEvent.getSlot();
|
final byte resultSlot = changeHeldSlotEvent.getSlot();
|
||||||
|
|
||||||
// If the held slot has been changed by the event, send the change to the player
|
// If the held slot has been changed by the event, send the change to the player
|
||||||
if (resultSlot != slot) {
|
if (resultSlot != slot) {
|
||||||
|
@ -6,11 +6,11 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
|||||||
|
|
||||||
public class HeldItemChangePacket implements ServerPacket {
|
public class HeldItemChangePacket implements ServerPacket {
|
||||||
|
|
||||||
public short slot;
|
public byte slot;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketWriter writer) {
|
public void write(PacketWriter writer) {
|
||||||
writer.writeShort(slot);
|
writer.writeByte(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user