Search in sources :

Example 1 with CustomNetHandlerPlayServer

use of ValkyrienWarfareBase.Interaction.CustomNetHandlerPlayServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EventsCommon method onPlayerTickEvent.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerTickEvent(PlayerTickEvent event) {
    if (!event.player.worldObj.isRemote && event.player != null) {
        EntityPlayerMP p = (EntityPlayerMP) event.player;
        try {
            if (!(p.connection instanceof CustomNetHandlerPlayServer)) {
                p.connection = new CustomNetHandlerPlayServer(p.connection);
            } else {
                CustomNetHandlerPlayServer customNetHandler = (CustomNetHandlerPlayServer) p.connection;
                if (p.interactionManager.getBlockReachDistance() == CustomNetHandlerPlayServer.dummyBlockReachDist && customNetHandler.ticksSinceLastTry == 2) {
                    p.interactionManager.setBlockReachDistance(((CustomNetHandlerPlayServer) p.connection).lastGoodBlockReachDist);
                }
                customNetHandler.ticksSinceLastTry++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Double[] pos = lastPositions.get(p);
        if (pos == null) {
            pos = new Double[3];
            lastPositions.put(p, pos);
        }
        try {
            if (pos[0] != p.posX || pos[2] != p.posZ) {
                // Player has moved
                if (Math.abs(p.posX) > 27000000 || Math.abs(p.posZ) > 27000000) {
                    // Player is outside of world border, tp them back
                    p.attemptTeleport(pos[0], pos[1], pos[2]);
                    p.addChatMessage(new TextComponentString("You can't go beyond 27000000 blocks because airships are stored there!"));
                }
            }
        } catch (NullPointerException e) {
            ValkyrienWarfareMod.VWLogger.log(Level.WARNING, "Nullpointer EventsCommon.java:onPlayerTickEvent");
        }
        pos[0] = p.posX;
        pos[1] = p.posY;
        pos[2] = p.posZ;
    }
}
Also used : CustomNetHandlerPlayServer(ValkyrienWarfareBase.Interaction.CustomNetHandlerPlayServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

CustomNetHandlerPlayServer (ValkyrienWarfareBase.Interaction.CustomNetHandlerPlayServer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1