@@ -32,6 +32,7 @@

import org.spout.api.protocol.MessageCodec;

import org.spout.vanilla.controller.living.player.GameMode;
import org.spout.vanilla.protocol.msg.StateChangeMessage;

public final class StateChangeCodec extends MessageCodec<StateChangeMessage> {
@@ -41,16 +42,16 @@ public StateChangeCodec() {

@Override
public StateChangeMessage decode(ChannelBuffer buffer) throws IOException {
byte state = buffer.readByte();
byte something = buffer.readByte();
return new StateChangeMessage(state, something);
byte reason = buffer.readByte();
byte gameMode = buffer.readByte();
return new StateChangeMessage(reason, GameMode.getById(gameMode));
}

@Override
public ChannelBuffer encode(StateChangeMessage message) throws IOException {
ChannelBuffer buffer = ChannelBuffers.buffer(2);
buffer.writeByte(message.getState());
buffer.writeByte(message.getGameMode());
buffer.writeByte(message.getReason());
buffer.writeByte(message.getGameMode().getId());
return buffer;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -29,20 +29,12 @@
import org.spout.api.player.Player;
import org.spout.api.protocol.MessageHandler;
import org.spout.api.protocol.Session;

import org.spout.vanilla.protocol.event.entity.EntityAnimationEvent;
import org.spout.vanilla.protocol.msg.EntityAnimationMessage;

public final class AnimateEntityMessageHandler extends MessageHandler<EntityAnimationMessage> {
@Override
public void handleServer(Session session, Player player, EntityAnimationMessage message) {
//TODO get target block and call onPlayerInteract
//TODO call AnimationEvent
EntityAnimationEvent event = new EntityAnimationEvent(message.getId(), EntityAnimationEvent.Animation.getById(message.getId()));
for (Player plr : Spout.getEngine().getOnlinePlayers()) {
if (!(plr.getName().equals(player.getName()))) {
plr.getNetworkSynchronizer().callProtocolEvent(event);
}
}
}
}
@@ -118,7 +118,7 @@ public void handleServer(Session session, Player player, BlockPlacementMessage m
if (!sendRevert && !oldBlock.isPlacementObstacle()) {
//if (EventFactory.onBlockCanBuild(target, placedId.getItemTypeId(), face).isBuildable()) {
//SpoutBlockState newState = BlockProperties.get(placedId.getItemTypeId()).getPhysics().placeAgainst(player, target.getState(), placedId, face);
//BlockPlaceEvent event = EventFactory.onBlockPlace(target, newState, against, player);
//PlayerBlockPlaceEvent event = EventFactory.onBlockPlace(target, newState, against, player);

//if (!event.isCancelled() && event.canBuild()) {
/*newState.update(true);
@@ -65,7 +65,7 @@ public void handleServer(Session session, Player player, EntityInteractionMessag
VanillaController temp = (VanillaController) clickedEntity.getController();
if (!temp.getParent().isDead()) {
temp.damage(damage);
temp.sendMessage(temp.getParent().getWorld().getPlayers(), new EntityAnimationMessage(temp.getParent().getId(), EntityAnimationMessage.ANIMATION_HURT), new EntityStatusMessage(temp.getParent().getId(), EntityStatusMessage.ENTITY_HURT));
temp.broadcastPacket(new EntityAnimationMessage(temp.getParent().getId(), EntityAnimationMessage.ANIMATION_HURT), new EntityStatusMessage(temp.getParent().getId(), EntityStatusMessage.ENTITY_HURT));
}
}
} else {
@@ -1,56 +1,56 @@
/*
* This file is part of Vanilla (http://www.spout.org/).
*
* Vanilla is licensed under the SpoutDev License Version 1.
*
* Vanilla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, 180 days after any changes are published, you can use the
* software, incorporating those changes, under the terms of the MIT license,
* as described in the SpoutDev License Version 1.
*
* Vanilla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License,
* the MIT license and the SpoutDev License Version 1 along with this program.
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license.
*/
package org.spout.vanilla.protocol.msg;

import org.spout.api.protocol.Message;

public final class HealthMessage extends Message {
private final short health, food;
private final float foodSaturation;

public HealthMessage(short health, short food, float foodSaturation) {
this.health = health;
this.food = food;
this.foodSaturation = foodSaturation;
}

public short getHealth() {
return health;
}

public short getFood() {
return food;
}

public float getFoodSaturation() {
return foodSaturation;
}

@Override
public String toString() {
return "HealthMessage{health=" + health + ",food=" + food + ",foodSaturation=" + foodSaturation + "}";
}
}
/*
* This file is part of Vanilla (http://www.spout.org/).
*
* Vanilla is licensed under the SpoutDev License Version 1.
*
* Vanilla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, 180 days after any changes are published, you can use the
* software, incorporating those changes, under the terms of the MIT license,
* as described in the SpoutDev License Version 1.
*
* Vanilla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License,
* the MIT license and the SpoutDev License Version 1 along with this program.
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license.
*/
package org.spout.vanilla.protocol.msg;

import org.spout.api.protocol.Message;

public final class PlayerHealthMessage extends Message {
private final short health, food;
private final float foodSaturation;

public PlayerHealthMessage(short health, short food, float foodSaturation) {
this.health = health;
this.food = food;
this.foodSaturation = foodSaturation;
}

public short getHealth() {
return health;
}

public short getFood() {
return food;
}

public float getFoodSaturation() {
return foodSaturation;
}

@Override
public String toString() {
return "PlayerHealthMessage{health=" + health + ",food=" + food + ",foodSaturation=" + foodSaturation + "}";
}
}
@@ -26,25 +26,36 @@
package org.spout.vanilla.protocol.msg;

import org.spout.api.protocol.Message;
import org.spout.vanilla.controller.living.player.GameMode;

public final class StateChangeMessage extends Message {
private final byte state, gameMode;
public static final byte INVALID_BED = 0;
public static final byte BEGIN_RAINING = 1;
public static final byte END_RAINING = 2;
public static final byte CHANGE_GAME_MODE = 3;
public static final byte ENTER_CREDITS = 4;
private final byte reason;
private GameMode gameMode;

public StateChangeMessage(byte state, byte gameMode) {
this.state = state;
public StateChangeMessage(byte reason, GameMode gameMode) {
this.reason = reason;
this.gameMode = gameMode;
}

public StateChangeMessage(byte reason) {
this(reason, GameMode.CREATIVE);
}

public byte getState() {
return state;
public byte getReason() {
return reason;
}

public byte getGameMode() {
public GameMode getGameMode() {
return gameMode;
}

@Override
public String toString() {
return "StateChangeMessage{state=" + state + ",gamemode=" + gameMode + "}";
return "StateChangeMessage{reason=" + reason + ",gamemode=" + gameMode.getId() + "}";
}
}
@@ -43,76 +43,12 @@
import org.spout.api.protocol.Message;
import org.spout.api.protocol.MessageCodec;

import org.spout.vanilla.controller.living.player.GameMode;
import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.controller.effect.EntityEffect;
import org.spout.vanilla.protocol.msg.AttachEntityMessage;
import org.spout.vanilla.protocol.msg.BlockActionMessage;
import org.spout.vanilla.protocol.msg.BlockChangeMessage;
import org.spout.vanilla.protocol.msg.BlockPlacementMessage;
import org.spout.vanilla.protocol.msg.ChangeItemMessage;
import org.spout.vanilla.protocol.msg.ChatMessage;
import org.spout.vanilla.protocol.msg.CloseWindowMessage;
import org.spout.vanilla.protocol.msg.CollectItemMessage;
import org.spout.vanilla.protocol.msg.CompressedChunkMessage;
import org.spout.vanilla.protocol.msg.CreateEntityMessage;
import org.spout.vanilla.protocol.msg.*;
import org.spout.api.protocol.common.message.CustomDataMessage;
import org.spout.vanilla.protocol.msg.DestroyEntityMessage;
import org.spout.vanilla.protocol.msg.DiggingMessage;
import org.spout.vanilla.protocol.msg.EnchantItemMessage;
import org.spout.vanilla.protocol.msg.EntityActionMessage;
import org.spout.vanilla.protocol.msg.EntityAnimationMessage;
import org.spout.vanilla.protocol.msg.EntityEffectMessage;
import org.spout.vanilla.protocol.msg.EntityEquipmentMessage;
import org.spout.vanilla.protocol.msg.EntityHeadYawMessage;
import org.spout.vanilla.protocol.msg.EntityInteractionMessage;
import org.spout.vanilla.protocol.msg.EntityMetadataMessage;
import org.spout.vanilla.protocol.msg.EntityRemoveEffectMessage;
import org.spout.vanilla.protocol.msg.EntityRotationMessage;
import org.spout.vanilla.protocol.msg.EntityStatusMessage;
import org.spout.vanilla.protocol.msg.EntityTeleportMessage;
import org.spout.vanilla.protocol.msg.EntityVelocityMessage;
import org.spout.vanilla.protocol.msg.ExperienceMessage;
import org.spout.vanilla.protocol.msg.ExperienceOrbMessage;
import org.spout.vanilla.protocol.msg.ExplosionMessage;
import org.spout.vanilla.protocol.msg.GroundMessage;
import org.spout.vanilla.protocol.msg.HandshakeMessage;
import org.spout.vanilla.protocol.msg.HealthMessage;
import org.spout.vanilla.protocol.msg.IdentificationMessage;
import org.spout.vanilla.protocol.msg.KickMessage;
import org.spout.vanilla.protocol.msg.LoadChunkMessage;
import org.spout.vanilla.protocol.msg.MapDataMessage;
import org.spout.vanilla.protocol.msg.MultiBlockChangeMessage;
import org.spout.vanilla.protocol.msg.OpenWindowMessage;
import org.spout.vanilla.protocol.msg.PingMessage;
import org.spout.vanilla.protocol.msg.PlayEffectMessage;
import org.spout.vanilla.protocol.msg.PlayerAbilityMessage;
import org.spout.vanilla.protocol.msg.PositionMessage;
import org.spout.vanilla.protocol.msg.PositionRotationMessage;
import org.spout.vanilla.protocol.msg.ProgressBarMessage;
import org.spout.vanilla.protocol.msg.CreativeMessage;
import org.spout.vanilla.protocol.msg.RelativeEntityPositionMessage;
import org.spout.vanilla.protocol.msg.RelativeEntityPositionRotationMessage;
import org.spout.vanilla.protocol.msg.RespawnMessage;
import org.spout.vanilla.protocol.msg.RotationMessage;
import org.spout.vanilla.protocol.msg.ServerListPingMessage;
import org.spout.vanilla.protocol.msg.SetWindowSlotMessage;
import org.spout.vanilla.protocol.msg.SetWindowSlotsMessage;
import org.spout.vanilla.protocol.msg.SpawnItemMessage;
import org.spout.vanilla.protocol.msg.SpawnLightningStrikeMessage;
import org.spout.vanilla.protocol.msg.SpawnMobMessage;
import org.spout.vanilla.protocol.msg.SpawnPaintingMessage;
import org.spout.vanilla.protocol.msg.SpawnPlayerMessage;
import org.spout.vanilla.protocol.msg.SpawnPositionMessage;
import org.spout.vanilla.protocol.msg.SpawnVehicleMessage;
import org.spout.vanilla.protocol.msg.StateChangeMessage;
import org.spout.vanilla.protocol.msg.StatisticMessage;
import org.spout.vanilla.protocol.msg.TileEntityDataMessage;
import org.spout.vanilla.protocol.msg.TimeMessage;
import org.spout.vanilla.protocol.msg.TransactionMessage;
import org.spout.vanilla.protocol.msg.UpdateSignMessage;
import org.spout.vanilla.protocol.msg.UseBedMessage;
import org.spout.vanilla.protocol.msg.PlayerListMessage;
import org.spout.vanilla.protocol.msg.WindowClickMessage;
import org.spout.vanilla.protocol.msg.PlayerHealthMessage;

public class VanillaProtocolTest {
private static final VanillaCodecLookupService CODEC_LOOKUP = new VanillaCodecLookupService();
@@ -125,7 +61,7 @@ public class VanillaProtocolTest {
new EntityEquipmentMessage(234, 3, 2, 3),
new SpawnPositionMessage(42, 42, 42),
new EntityInteractionMessage(1123, 4455, true),
new HealthMessage((short) 1, (short) 2, 3.4F),
new PlayerHealthMessage((short) 1, (short) 2, 3.4F),
new RespawnMessage(89, (byte) 0, (byte) 1, 128, "VERYFANCY"),
new GroundMessage(true),
new PositionMessage(128, 256, 512, 3.4D, true),
@@ -165,7 +101,7 @@ public class VanillaProtocolTest {
new BlockActionMessage(1, 2, 3, (byte) 4, (byte) 5),
new ExplosionMessage(3, 4, 5, 24, new byte[]{1, 2, 3, 1, 1, 2, 1, 1, 1}),
new PlayEffectMessage(34566, 1, 2, 34, 5),
new StateChangeMessage((byte) 3, (byte) 1),
new StateChangeMessage(StateChangeMessage.CHANGE_GAME_MODE, GameMode.CREATIVE),
new SpawnLightningStrikeMessage(34, 1, 23, 45, 55),
new OpenWindowMessage(1, 2, "container.furnace", 42),
new CloseWindowMessage(23),