use of org.dragonet.net.packet.minecraft.WindowItemsPacket in project Dragonet-Legacy by DragonetMC.
the class SetWindowContentsMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(SetWindowContentsMessage packet) {
if (packet.id == 0) {
//Inventory Items(Included hotbar)
WindowItemsPacket pkInventory = new WindowItemsPacket();
pkInventory.windowID = PEWindowConstantID.PLAYER_INVENTORY;
pkInventory.slots = new PEInventorySlot[InventoryType.SlotSize.PLAYER];
for (int i = 9; i <= 44; i++) {
if (packet.items[i] != null) {
pkInventory.slots[i - 9] = new PEInventorySlot((short) (packet.items[i].getTypeId() & 0xFFFF), (byte) (packet.items[i].getAmount() & 0xFF), packet.items[i].getDurability());
} else {
pkInventory.slots[i - 9] = new PEInventorySlot();
}
}
pkInventory.hotbar = new int[9];
for (int i = 36; i <= 44; i++) {
pkInventory.hotbar[i - 36] = i - 9;
}
//Armor
WindowItemsPacket pkArmorInv = new WindowItemsPacket();
pkArmorInv.windowID = PEWindowConstantID.PLAYER_ARMOR;
pkArmorInv.slots = new PEInventorySlot[4];
for (int i = 5; i <= 8; i++) {
if (packet.items[i] != null) {
pkArmorInv.slots[i - 5] = new PEInventorySlot((short) (packet.items[i].getTypeId() & 0xFFFF), (byte) (packet.items[i].getAmount() & 0xFF), packet.items[i].getDurability());
} else {
pkArmorInv.slots[i - 5] = new PEInventorySlot();
}
}
return new PEPacket[] { pkInventory, pkArmorInv };
}
//TODO: Implement other types of inventory
//switch(this.getSession().getPlayer().)
System.out.println("Updating window content for " + packet.id + ", which has " + packet.items.length + " slots. ");
return null;
}
use of org.dragonet.net.packet.minecraft.WindowItemsPacket in project Dragonet-Legacy by DragonetMC.
the class DragonetSession method setPlayer.
/**
* Sets the player associated with this session.
*
* @param profile The player's profile with name and UUID information.
* @throws IllegalStateException if there is already a player associated
* with this session.
*/
@Override
public void setPlayer(PlayerProfile profile) {
if (this.getPlayer() != null) {
throw new IllegalStateException("Cannot set player twice");
}
// initialize the player
PlayerDataService.PlayerReader reader = this.getServer().getPlayerDataService().beginReadingData(profile.getUniqueId());
//this.player = new GlowPlayer(this, profile, reader);
this.player = new DragonetPlayer(this, profile, reader);
// login event
PlayerLoginEvent event = EventFactory.onPlayerLogin(player, this.getHostname());
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
disconnect(event.getKickMessage(), true);
return;
}
// Dragonet-Add: or same username
for (GlowPlayer other : getServer().getOnlinePlayers()) {
if ((other != player && other.getUniqueId().equals(player.getUniqueId())) || other.getName().equalsIgnoreCase(player.getName())) {
other.getSession().disconnect("You logged in from another location.", true);
break;
}
}
player.join(this, reader);
WindowItemsPacket creativeInv = null;
//Send the StartGamePacket
StartGamePacket pkStartGame = new StartGamePacket();
pkStartGame.seed = 0;
pkStartGame.generator = 1;
if (this.player.getGameMode().equals(GameMode.CREATIVE)) {
pkStartGame.gamemode = 1;
creativeInv = WindowItemsPacket.CREATIVE_INVENTORY;
} else if (this.player.getGameMode().equals(GameMode.SURVIVAL) && this.player.getGameMode().equals(GameMode.ADVENTURE)) {
pkStartGame.gamemode = 0;
} else {
creativeInv = new WindowItemsPacket();
creativeInv.windowID = PEWindowConstantID.PLAYER_CREATIVE;
}
pkStartGame.eid = (long) this.player.getEntityId();
pkStartGame.spawnX = this.player.getWorld().getSpawnLocation().getBlockX();
pkStartGame.spawnY = this.player.getWorld().getSpawnLocation().getBlockY();
pkStartGame.spawnZ = this.player.getWorld().getSpawnLocation().getBlockZ();
pkStartGame.x = (float) this.player.getLocation().getX();
pkStartGame.y = (float) this.player.getLocation().getY();
pkStartGame.z = (float) this.player.getLocation().getZ();
this.send(pkStartGame);
if (creativeInv != null) {
this.send(creativeInv);
}
//Send crafting recipie list
sendRecipies();
//Send Time
SetTimePacket pkTime = new SetTimePacket((int) (this.getPlayer().getWorld().getTime() & 0xFFFFFFFF), false);
this.send(pkTime);
//Send Spawn Position
SetSpawnPositionPacket pkSpawnPos = new SetSpawnPositionPacket();
pkSpawnPos.x = this.player.getLocation().getBlockX();
pkSpawnPos.y = this.player.getLocation().getBlockY();
pkSpawnPos.z = this.player.getLocation().getBlockZ();
this.send(pkSpawnPos);
//Send Health
SetHealthPacket pkHealth = new SetHealthPacket((int) Math.floor(this.getPlayer().getHealth()));
this.send(pkHealth);
//Send Difficulty Packet
SetDifficultyPacket pkDifficulty = new SetDifficultyPacket();
pkDifficulty.difficulty = this.getServer().getDifficulty().getValue();
this.send(pkDifficulty);
player.getWorld().getRawPlayers().add(player);
GlowServer.logger.log(Level.INFO, "{0} [{1}] connected from Minecraft PE, UUID: {2}", new Object[] { player.getName(), this.getAddress(), player.getUniqueId() });
//Preprare chunks
this.chunkManager.prepareLoginChunks();
// message and user list
String message = EventFactory.onPlayerJoin(player).getJoinMessage();
if (message != null && !message.isEmpty()) {
this.getServer().broadcastMessage(message);
}
// todo: display names are included in the outgoing messages here, but
// don't show up on the client. A workaround or proper fix is needed.
Message addMessage = new UserListItemMessage(UserListItemMessage.Action.ADD_PLAYER, player.getUserListEntry());
List<UserListItemMessage.Entry> entries = new ArrayList<>();
for (GlowPlayer other : this.getServer().getOnlinePlayers()) {
if (other != player && other.canSee(player)) {
other.getSession().send(addMessage);
}
if (player.canSee(other)) {
entries.add(other.getUserListEntry());
}
}
send(new UserListItemMessage(UserListItemMessage.Action.ADD_PLAYER, entries));
RakNetInterface.sendName();
}
use of org.dragonet.net.packet.minecraft.WindowItemsPacket in project Dragonet-Legacy by DragonetMC.
the class DragonetSession method sendInventory.
public void sendInventory() {
if (this.getPlayer() == null) {
return;
}
if (this.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
return;
}
WindowItemsPacket pkItems = new WindowItemsPacket();
pkItems.windowID = PEWindowConstantID.PLAYER_INVENTORY;
pkItems.slots = new PEInventorySlot[InventoryType.SlotSize.PLAYER];
pkItems.hotbar = new int[9];
for (int i = 9; i <= 35; i++) {
if (this.getPlayer().getInventory().getContents()[i] != null) {
pkItems.slots[i - 9] = new PEInventorySlot((short) (this.getPlayer().getInventory().getContents()[i].getTypeId() & 0xFFFF), (byte) (this.getPlayer().getInventory().getContents()[i].getAmount() & 0xFF), this.getPlayer().getInventory().getContents()[i].getDurability());
} else {
pkItems.slots[i - 9] = new PEInventorySlot();
}
}
for (int i = 0; i <= 8; i++) {
if (this.getPlayer().getInventory().getContents()[i] != null) {
pkItems.slots[i + 27] = new PEInventorySlot((short) (this.getPlayer().getInventory().getContents()[i].getTypeId() & 0xFFFF), (byte) (this.getPlayer().getInventory().getContents()[i].getAmount() & 0xFF), this.getPlayer().getInventory().getContents()[i].getDurability());
} else {
pkItems.slots[i + 27] = new PEInventorySlot();
}
}
for (int i = 0; i <= 8; i++) {
pkItems.hotbar[i] = 44 - 8 + i;
}
this.send(pkItems);
}
Aggregations