Search in sources :

Example 1 with TileEntityGlobalChatDetector

use of lumien.randomthings.tileentity.TileEntityGlobalChatDetector in project Random-Things by lumien231.

the class RTEventHandler method chatEvent.

@SubscribeEvent
public void chatEvent(ServerChatEvent event) {
    EntityPlayerMP player = event.getPlayer();
    BlockPos below = player.getPosition().down();
    IBlockState state = player.world.getBlockState(below);
    ItemStack flooDust = player.getHeldItemMainhand();
    if (!player.world.getEntitiesWithinAABB(EntityTemporaryFlooFireplace.class, player.getEntityBoundingBox().grow(0.5)).isEmpty()) {
        String target = event.getMessage();
        FlooNetworkHandler networkHandler = FlooNetworkHandler.get(player.world);
        boolean success = networkHandler.teleport(player.world, null, null, player, target);
        if (success) {
            event.setCanceled(true);
        }
    } else if ((player.capabilities.isCreativeMode || (!flooDust.isEmpty() && flooDust.getItem() instanceof ItemIngredient && flooDust.getItemDamage() == ItemIngredient.INGREDIENT.FLOO_POWDER.id)) && state.getBlock() == ModBlocks.flooBrick) {
        String target = event.getMessage();
        TileEntityFlooBrick te = (TileEntityFlooBrick) player.world.getTileEntity(below);
        UUID firePlaceUUID = te.getFirePlaceUid();
        if (firePlaceUUID != null) {
            FlooNetworkHandler networkHandler = FlooNetworkHandler.get(player.world);
            TileEntity masterTE = networkHandler.getFirePlaceTE(player.world, firePlaceUUID);
            if (masterTE instanceof TileEntityFlooBrick) {
                TileEntityFlooBrick masterBrick = ((TileEntityFlooBrick) masterTE);
                if (masterBrick.isMaster()) {
                    boolean success = networkHandler.teleport(player.world, masterBrick.getPos(), masterBrick, player, target);
                    if (success) {
                        if (!player.capabilities.isCreativeMode) {
                            flooDust.shrink(1);
                        }
                    }
                    event.setCanceled(true);
                }
            }
        }
        return;
    }
    if (!(player instanceof FakePlayer) && player.getGameProfile() != null) {
        Iterator<TileEntityChatDetector> iterator = TileEntityChatDetector.detectors.iterator();
        while (iterator.hasNext()) {
            TileEntityChatDetector chatDetector = iterator.next();
            if (chatDetector.isInvalid()) {
                iterator.remove();
            } else {
                if (chatDetector.checkMessage(event.getPlayer(), event.getMessage())) {
                    event.setCanceled(true);
                }
            }
        }
        Iterator<TileEntityGlobalChatDetector> iteratorGlobal = TileEntityGlobalChatDetector.detectors.iterator();
        while (iteratorGlobal.hasNext()) {
            TileEntityGlobalChatDetector chatDetector = iteratorGlobal.next();
            if (chatDetector.isInvalid()) {
                iteratorGlobal.remove();
            } else {
                if (chatDetector.checkMessage(event.getPlayer(), event.getMessage())) {
                    event.setCanceled(true);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TileEntityFlooBrick(lumien.randomthings.tileentity.TileEntityFlooBrick) TileEntityChatDetector(lumien.randomthings.tileentity.TileEntityChatDetector) FakePlayer(net.minecraftforge.common.util.FakePlayer) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityGlobalChatDetector(lumien.randomthings.tileentity.TileEntityGlobalChatDetector) FlooNetworkHandler(lumien.randomthings.handler.floo.FlooNetworkHandler) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemIngredient(lumien.randomthings.item.ItemIngredient) UUID(java.util.UUID) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

UUID (java.util.UUID)1 FlooNetworkHandler (lumien.randomthings.handler.floo.FlooNetworkHandler)1 ItemIngredient (lumien.randomthings.item.ItemIngredient)1 TileEntityChatDetector (lumien.randomthings.tileentity.TileEntityChatDetector)1 TileEntityFlooBrick (lumien.randomthings.tileentity.TileEntityFlooBrick)1 TileEntityGlobalChatDetector (lumien.randomthings.tileentity.TileEntityGlobalChatDetector)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1