summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/packet/MessageGuiButtonWithString.java
blob: 2df2b77e034857879a486681a3b2460edf4baf80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package jp.plusplus.fbs.packet;

import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import jp.plusplus.fbs.FBS;
import jp.plusplus.fbs.container.ContainerContract;
import jp.plusplus.fbs.container.ContainerWarp;
import jp.plusplus.fbs.container.spirit.ContainerSpiritLearn;
import jp.plusplus.fbs.exprop.FBSEntityProperties;
import jp.plusplus.fbs.exprop.SanityManager;
import jp.plusplus.fbs.spirit.SpiritManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;

/**
 * Created by plusplus_F on 2015/10/23.
 */
public class MessageGuiButtonWithString implements IMessage {
    protected int index;
    protected String name;

    public MessageGuiButtonWithString(){}
    public MessageGuiButtonWithString(int index, String str){
        this.index=index;
        this.name=str;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        index= ByteBufUtils.readVarInt(buf, 4);
        name=ByteBufUtils.readUTF8String(buf);
    }

    @Override
    public void toBytes(ByteBuf buf) {
        ByteBufUtils.writeVarInt(buf, index, 4);
        ByteBufUtils.writeUTF8String(buf, name);
    }

    public static class Handler implements IMessageHandler<MessageGuiButtonWithString, IMessage>{
        @Override
        public IMessage onMessage(MessageGuiButtonWithString message, MessageContext ctx) {
            Container con=ctx.getServerHandler().playerEntity.openContainer;
            EntityPlayer player=ctx.getServerHandler().playerEntity;

            if(con instanceof ContainerWarp){
                //時空間の航行
                FBSEntityProperties prop=FBSEntityProperties.get(player);
                prop.getDestinations().get(message.index).setName(message.name);
                SanityManager.sendPacket(player);
            }
            else if(con instanceof ContainerContract){
                //精霊との契約
                String ch=((ContainerContract) con).contract(message.name, player);
            }
            else if(con instanceof ContainerSpiritLearn){
                ContainerSpiritLearn c=(ContainerSpiritLearn)con;
                //FBS.logger.info(message.name);
                c.learn(message.name);
            }

            return null;
        }
    }
}