Jump to content

Can't get field 'playerEntity' from ServerHandler [1.7.10]


stepan1404
 Share

Recommended Posts

I run this code on server handler on Thermos (1614-57) core and take this error

java.lang.NoSuchFieldError: playerEntity

 

Message class

Spoiler

 


package ru.stepan1404.magictab.network.shop;

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 net.minecraft.entity.player.EntityPlayer;
import org.hibernate.Session;
import org.hibernate.query.Query;
import ru.stepan1404.magictab.client.cache.shop.NetworkCache;
import ru.stepan1404.magictab.client.core.util.MagicScreens;
import ru.stepan1404.magictab.server.core.MagicTab;
import ru.stepan1404.magictab.server.shop.dao.cart.ItemCart;
import ru.stepan1404.magictab.server.shop.dao.cart.PlayerCart;

import java.util.ArrayList;
import java.util.List;

public class CartMessage {

    public static class CartMessageRequest implements IMessage, IMessageHandler<CartMessageRequest, CartMessageResponse> {

        public CartMessageRequest(){}

        @Override
        public void fromBytes(ByteBuf buf) {}

        @Override
        public void toBytes(ByteBuf buf) {}

        @Override
        public CartMessageResponse onMessage(CartMessageRequest message, MessageContext ctx) {
            Session session = MagicTab.getMagicTab().getMagicHiber().getSessionFactory().openSession();
            Query query = session.createQuery("FROM PlayerCart p where p.uuid = :uid");
            EntityPlayer player = ctx.getServerHandler().playerEntity;
            query.setParameter("uid", player.getGameProfile().getId().toString());
            PlayerCart cart = (PlayerCart) query.uniqueResult();
            List<ru.stepan1404.magictab.network.shop.dto.cart.ItemCart> itemCarts = new ArrayList<>();

            for(ItemCart item : cart.getItems()){
                itemCarts.add(new ru.stepan1404.magictab.network.shop.dto.cart.ItemCart(item.getId(), item.getMaterialName(), item.getDamage(), item.getNbt(), item.getCount(), item.getPrice()));
            }

            session.close();
            return new CartMessageResponse(itemCarts);
        }

    }

    public static class CartMessageResponse implements IMessage, IMessageHandler<CartMessageResponse, IMessage> {

        List<ru.stepan1404.magictab.network.shop.dto.cart.ItemCart> cart = new ArrayList<>();

        public CartMessageResponse() {}

        public CartMessageResponse(List<ru.stepan1404.magictab.network.shop.dto.cart.ItemCart> itemCarts) {
            this.cart = itemCarts;
        }

        @Override
        public void fromBytes(ByteBuf buf) {
            int size = buf.readInt();

            for(int i = 0; i < size; i++){
                ru.stepan1404.magictab.network.shop.dto.cart.ItemCart itemCart = new ru.stepan1404.magictab.network.shop.dto.cart.ItemCart();
                itemCart.setId(buf.readInt());
                itemCart.setMaterialName(ByteBufUtils.readUTF8String(buf));
                itemCart.setDamage(buf.readInt());
                itemCart.setNbt(ByteBufUtils.readUTF8String(buf));
                itemCart.setCount(buf.readInt());
                itemCart.setPrice(buf.readInt());

                this.cart.add(itemCart);
            }
        }

        @Override
        public void toBytes(ByteBuf buf) {
            buf.writeInt(this.cart.size());

            for(ru.stepan1404.magictab.network.shop.dto.cart.ItemCart itemCart : cart){
                buf.writeInt(itemCart.getId());
                ByteBufUtils.writeUTF8String(buf, itemCart.getMaterialName());
                buf.writeInt(itemCart.getDamage());
                ByteBufUtils.writeUTF8String(buf, itemCart.getNbt());
                buf.writeInt(itemCart.getCount());
                buf.writeInt(itemCart.getPrice());
            }
        }

        @Override
        public IMessage onMessage(CartMessageResponse message, MessageContext ctx) {
            NetworkCache.setCartItems(message.cart);
            MagicScreens.addCartToScreen();
            return null;
        }

    }

}


Network class

Spoiler

public class MagicNetworkRegistry {

    @Getter
    private SimpleNetworkWrapper network;
    private static int id = -1;

    public MagicNetworkRegistry(){
        this.network = NetworkRegistry.INSTANCE.newSimpleChannel(Constants.MODID);

        this.registerServerMessages();
        this.registerClientMessages();
    }

    private void registerServerMessages() {
        this.network.registerMessage(BalanceMessage.BalanceMessageRequest.class, BalanceMessage.BalanceMessageRequest.class, this.getNextID(), Side.SERVER);
        this.network.registerMessage(CategoryMessage.CategoryMessageRequest.class, CategoryMessage.CategoryMessageRequest.class, this.getNextID(), Side.SERVER);
        this.network.registerMessage(CartMessage.CartMessageRequest.class, CartMessage.CartMessageRequest.class, this.getNextID(), Side.SERVER);
        this.network.registerMessage(AddToCartMessage.AddToCartMessageRequest.class, AddToCartMessage.AddToCartMessageRequest.class, this.getNextID(), Side.SERVER);
        this.network.registerMessage(ApplyBuyMessage.ApplyBuyMessageRequest.class, ApplyBuyMessage.ApplyBuyMessageRequest.class, this.getNextID(), Side.SERVER);
        this.network.registerMessage(CancelBuyMessage.CancelBuyMessageRequest.class, CancelBuyMessage.CancelBuyMessageRequest.class, this.getNextID(), Side.SERVER);
        this.network.registerMessage(RemoveFromCartMessage.RemoveFromCartMessageRequest.class, RemoveFromCartMessage.RemoveFromCartMessageRequest.class, this.getNextID(), Side.SERVER);
    }

    private void registerClientMessages() {
        this.network.registerMessage(BalanceMessage.BalanceMessageResponse.class, BalanceMessage.BalanceMessageResponse.class, this.getNextID(), Side.CLIENT);
        this.network.registerMessage(CategoryMessage.CategoryMessageResponse.class, CategoryMessage.CategoryMessageResponse.class, this.getNextID(), Side.CLIENT);
        this.network.registerMessage(CartMessage.CartMessageResponse.class, CartMessage.CartMessageResponse.class, this.getNextID(), Side.CLIENT);
        this.network.registerMessage(AddToCartMessage.AddToCartMessageResponse.class, AddToCartMessage.AddToCartMessageResponse.class, this.getNextID(), Side.CLIENT);
        this.network.registerMessage(ApplyBuyMessage.ApplyBuyMessageResponse.class, ApplyBuyMessage.ApplyBuyMessageResponse.class, this.getNextID(), Side.CLIENT);
        this.network.registerMessage(CancelBuyMessage.CancelBuyMessageResponse.class, CancelBuyMessage.CancelBuyMessageResponse.class, this.getNextID(), Side.CLIENT);
        this.network.registerMessage(RemoveFromCartMessage.RemoveFromCartMessageResponse.class, RemoveFromCartMessage.RemoveFromCartMessageResponse.class, this.getNextID(), Side.CLIENT);
    }

    public <REQ extends IMessage, REPLY extends IMessage> void registerCustomMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side){
        this.network.registerMessage(messageHandler, requestMessageType, this.getNextID(), side);
    }

    private int getNextID(){
        return id++;
    }

}

 

Can anyone help me? I dissapointed :D.

I think that this error of Thermos, but i want to ask your before.
 

Edited by stepan1404
add message
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.